HTMLCollection长度返回0

时间:2020-03-05 16:28:04

标签: jquery html

在添加其他信息之前,我之前的帖子已被删除,但让我们再试一次...

我看过其他与此类似的帖子,但我的调整未成功。

var table = document.getElementById("report-table");
var rows = table.getElementsByTagName("tr");
console.log(rows.length);
console.log(rows);

0

HTMLCollection []
长度:1077

我的表是使用Jquery + AJAX填充的。我以为这可能是由于脚本放置引起的,但我在表填充完成后将其移到了并且结果相同。

编辑

$.ajax({
    url: 'test.php',
    type: 'post',
    data: {"order":order, "json":json},
    success: function(json){
        var js = Object.values(JSON.parse(json));
        js = JSON.parse(json);
        js.forEach(function(element){   
            var title = element['title'];
            var date = element['date_stamp'];
            $('#report-table').append('<tr class="report-item"><td>&emsp;'+title+'</td><td>'+date+'</td></tr>');
        });             
    }
});
var table = document.getElementById("report-table");
var rows = table.getElementsByTagName("tr");
console.log(rows.length);
console.log(rows);

HTML

<table class="report-table">
    <tr class="report-head">
        <th colspan="2">Report</th>
        <th colspan="2" class="right">List By : 
            <select id="sort-select" onchange="sort(json)">
            ...
            </select>
        </th>
    </tr>
</table>
<div class="my-table-responsive">
    <table id="report-table" class="report-table">
    </table>
</div>  

0 个答案:

没有答案