課程
/前端開發(fā)
/JavaScript
/瀑布流布局
為什么我跟老師打的一模一樣,chrom報(bào)錯(cuò),說getElementsByTagName() unll
2017-04-24
源自:瀑布流布局 2-3
正在回答
我有個(gè)方法,試試吧var oParent=document.getElementById('parent');當(dāng)中的引號(hào)去掉,他們就能找到main元素,然后就正常了
我的也是這樣
window.onload=function(){
waterfall('main','box');
}
function waterfall(parent,box){
//取出class為box的元素
var oParent=document.getElementById('parent');
var oBoxs=getByClass(oParent,box);
//計(jì)算整個(gè)頁(yè)面顯示的列數(shù)(頁(yè)面的款的除以每個(gè)盒子的寬度)
var oBoxW=oBoxs[0].offsetWidth;
console.log(oBoxw);
function getByClass(parent,clsName){
var boxArr=new Array();
var oElements=parent.getElementsByTagName("*");
for(var i=0;i<oElements.length;i++){
if (oElements[i].className==clsName){
boxArr.push(oElements[i]);
return boxArr;
顯示為null
貼代碼看下
舉報(bào)
瀑布流布局是網(wǎng)站比較流行的一種布局方式,教你實(shí)現(xiàn)三大方式
1 回答getElementsByTagName報(bào)錯(cuò)
5 回答Uncaught TypeError: Cannot read property 'getElementsByTagName' of undefined
1 回答mian.js:18 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
4 回答老是提示 Cannot read property 'getElementsByTagName' of null
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-05-10
我有個(gè)方法,試試吧var oParent=document.getElementById('parent');當(dāng)中的引號(hào)去掉,他們就能找到main元素,然后就正常了
2017-04-28
我的也是這樣
window.onload=function(){
waterfall('main','box');
}
function waterfall(parent,box){
//取出class為box的元素
var oParent=document.getElementById('parent');
var oBoxs=getByClass(oParent,box);
//計(jì)算整個(gè)頁(yè)面顯示的列數(shù)(頁(yè)面的款的除以每個(gè)盒子的寬度)
var oBoxW=oBoxs[0].offsetWidth;
console.log(oBoxw);
}
function getByClass(parent,clsName){
var boxArr=new Array();
var oElements=parent.getElementsByTagName("*");
for(var i=0;i<oElements.length;i++){
if (oElements[i].className==clsName){
boxArr.push(oElements[i]);
}
}
return boxArr;
}
顯示為null
2017-04-25
貼代碼看下