var js = document.getElementById('test-p');
var arr = document.getElementsByClassName("c-red c-green")[0].children;
var haskell = document.getElementsByClassName("c-green")[1].lastElementChild;
上面的可以,
为什么第二行改为 var arr = document.getElementsByClassName("c-red c-green").children;就不行了,是不是数组型的节点不能去用(.children)
getElementsByClassName返回的是个element数组,数组怎么会有子element呢
返回的真的是个数组吗?为什么使用Array.isArray(arr);判断失败
返回的不是真正的数组,所以无法改变内容
由于JS是动态语言,任何对象都可以加上一些属性和方法让它看起来像数组,但实际上不是真正的数组
Sign in to make a reply
ting挺123
var js = document.getElementById('test-p');
var arr = document.getElementsByClassName("c-red c-green")[0].children;
var haskell = document.getElementsByClassName("c-green")[1].lastElementChild;
上面的可以,
为什么第二行改为 var arr = document.getElementsByClassName("c-red c-green").children;就不行了,是不是数组型的节点不能去用(.children)