querySelectorAll的结果遍历时对象为空
document.querySelectorAll(".box")得到的不是数组,是nodelist,虽然可以类似数组的for,但真的不是数组,不能直接对其使用数组的方法forEach,如果我们需要转换为数组,我们可以用Array.prototype.slice.call来辅助就可以了。
https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
var divs = document.querySelectorAll('div');
[].forEach.call(divs, function(div) {
// do whatever
div.style.color = "red";
});
Android平台通过native.js实现接收系统消息,如监听安装卸载apk事件
http://ask.dcloud.net.cn/article/222
0 个评论
要回复文章请先登录或注册