getElementsByTagName報錯
Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
為什么我寫的老是出現(xiàn)這個報錯求解答,老師的代碼運行很正常。
function getByClass(obj, cls) {
?? ?var elements = obj.getElementsByTagName("*");
?? ?var pins = [];
?? ?for(i = 0; i < elements.length; i++) {
?? ??? ?if (elements[i].className == cls) {
?? ??? ??? ?pins.push(elements[i]);
?? ??? ?}
?? ?};
2016-09-04
沒獲取到obj這個對象吧