首页 > 解决方案 > java脚本中的querySelectorAll()返回零

问题描述

我使用 JS 在 html 页面中添加了元素,然后我使用查询 Selector All("element . class name") 来访问该元素,但它返回零。但是,我的网页中显示的元素。

var listItems=document.querySelectorAll(".list-items");
var x=listItems[0].querySelectorAll("img.list-item-img").length;
console.log(x);
<div class="list-items" id="mostReleaseList">
                    <!-- her will be tags by JS -->
</div>

标签: javascripthtml

解决方案


推荐阅读