反復檢查,不知道哪里錯了
window.onload?=?function(){ ??waterfall('main','box'); } function?waterfall(parent,box){ ??//將main下所有class=box的元素取出來 ??var?oParent?=?document.getElementById(parent); ??var?oBox?=?getbyclass(oParent,box); ??console.log(oBox.length); } function?getbyclass(parent,clsname){ ??var?boxarr?=?[];//用來存儲所有class?=?box?的元素 ????? ?????oElements?=?parent.getElementsByTagName("*"); ?????for?(var?i?=?0;?i?<?oElements.length;?i++)?{ ???????if?(oElements[i].className?==?clsname)?{ ??????????boxarr.push(oElements[i]); ???????} ?????} ?????return?boxarr; }
報錯:
Uncaught?TypeError:?Cannot?read?property?'getElementsByTagName'?of?null ????at?getbyclass?(index.js:18) ????at?waterfall?(index.js:10) ????at?window.onload?(index.js:2)
2017-07-20
第十一行 box 是字符串
2017-07-20
。。。。知道哪里錯了