所以 js 代碼從本地 api 獲取 json 數據并以表格格式顯示數據,在桌面上一切正常,但在移動設備上不顯示任何數據。我嘗試了一切,但這個 js 代碼有問題。我不明白出了什么問題,html 頁面的其余部分在移動設備上加載得很好。我應該對代碼進行任何更改嗎?function getUrl(start = 0) {? ? return 'http://localhost/login_registration_system_LAMP/api.php';}function getData(url)?{? ? fetch(url)? ? ? ? .then(response => response.json())? ? ? ? .then(data => loadDataIntoTable(data))? ? ? ? .catch(err => console.log(err));}function loadDataIntoTable(data) {? ? let coinprodName = [];? ? let coinprice = [];? ? let coinper = [];? ? let coinPerson = [];? ? let coinphone = [];? ? let coinsize = [];? ? let coinbrand = [];? ? let coinspecial = [];? ? let coinlife = [];? ? let coinmoq = [];? ? data.forEach((coin) => {? ? ? ? coinprodName.push(coin.product_name);? ? ? ? coinprice.push(coin.price);? ? ? ? coinper.push(coin.per);? ? ? ? coinPerson.push(coin.person_name);? ? ? ? coinphone.push(coin.phone);? ? ? ? coinsize.push(coin.size);? ? ? ? coinbrand.push(coin.brand);? ? ? ? coinspecial.push(coin.special);? ? ? ? coinlife.push(coin.life);? ? ? ? coinmoq.push(coin.moq);? ? });? ? let tableBody = document.getElementById('crypto-table-body');? ? let html = "";? ? for(let i = 0; i < coinmoq.length; i++) {? ? ? ? html += "<tr>";? ? ? ? html += "<td>" + coinprodName[i] + "</td>";? ? ? ? html += "<td>" + coinprice[i] + "</td>";? ? ? ? html += "<td>" + coinper[i] + "</td>";? ? ? ? html += "<td>" + coinPerson[i] + "</td>";? ? ? ? html += "<td>" + coinphone[i] + "</td>";? ? ? ? html += "<td>" + coinsize[i] + "</td>";? ? ? ? html += "<td>" + coinbrand[i] + "</td>";? ? ? ? html += "<td>" + coinspecial[i] + "</td>";? ? ? ? html += "<td>" + coinlife[i] + "</td>";? ? ? ? html += "<td>" + coinmoq[i] + "</td>";? ? ? ??? ? ? ??? ? ? ? html += "</tr>";? ? }? ? tableBody.innerHTML = html;}function init() {? ? const url = getUrl();? ? getData(url);}init();
Js腳本適用于桌面但不適用于移動設備
GCT1015
2023-06-09 17:36:30