當我的數據來自json和我試圖使用此代碼爲我的數據表添加行時。但它沒有奏效。我怎樣才能解決這個問題 ?使用javascript將行添加到html表格
<table style="width:300px" >
<thead>
<th>
Name
</th>
</thead>
<tbody id="location">
</tbody>
</table>
$.ajax(
{
type: "GET",
url: 'http://jsonplaceholder.typicode.com/users',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
var trHTML = '';
for (var i = 1; i > data.length; i++) {
console.log(data[i].name);
trHTML += '<tr><td><span>' + data[i].name + '</span></td></tr>';
};
$('#location tbody').append(trHTML);
},
error: function (msg) {
alert(msg.responseText);
}
});
我的實際目標是將行footable數據表插件,但我不能修復它。
將'$('#location tbody')。append(trHTML)'改爲'$('#location')。append(trHTML)' – Azim
.length – Rakshith
i