为了账号安全,请及时绑定邮箱和手机立即绑定

Uncaught TypeError: Cannot read property 'getElementsByTagName' of null,一直报这个错,有人遇到一样的吗?用google/firefox都试过了

// 获取class的函数,这是因为getElementByClassName针对IE10之前的无效
function getByClass(clsName,parent){
   var oParent=parent?document.getElementById(parent):document,
      eles=[],
      elements=oParent.getElementsByTagName('*');

   for (var i=0,l=elements.length;i<l;i++){
      if (elements[i].className==clsName){
          eles.push(elements[i]);
      }
   }
return eles;
}

window.onload=drag()

function drag(){
    var oTitle=getByClass('login_logo_webqq','loginPanel')[0];
    oTitle.onmousedown=fnDown;

}
//鼠标按下时的函数
function fnDown(){
    document.onmousemove=function(event){
         event=event||window.event;
         document.title=event.clientX+','+event.clientY;
    }
}


正在回答

1 回答

自己搞出来了,大概原因就是需要html先全部加载出来最后才可以取这个元素,把index.html的script标签放在html中的最后就可以了。。

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Uncaught TypeError: Cannot read property 'getElementsByTagName' of null,一直报这个错,有人遇到一样的吗?用google/firefox都试过了

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号