第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JS中,提示錯誤:The node to be removed is not a child of this node.

JS中,提示錯誤:The node to be removed is not a child of this node.

jeck貓 2018-12-07 06:05:13
我今天寫了一個彈幕效果,結果老是提示標題的那個錯誤 我的代碼如下:提示的是 danmu.removeChild(obj);這一句錯誤,大神告訴我為什么錯誤啊。。。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>仿彈幕效果</title> <style> *{margin: 0;padding: 0;list-style: none;} html,body{width: 100%;height: 100%;} body{background-color: #000;font-family: '微軟雅黑';} #danmu{position: relative;height: 100%;width: 100%;overflow: hidden;font-size: 50px;} #danmu .newli{background-color: #fff;height: 50px;line-height: 50px;position: absolute;overflow: hidden;} </style> </head> <body> <div id="danmu"></div> <script> var danmu=document.getElementById('danmu'); var winH=danmu.clientHeight; var timer1=null; var speak=['哇塞好牛逼啊','好帥啊','前方高能','hahahahaha','哈哈哈哈','風流倜儻','我愛你阿啊啊啊','哈哈哈']; function insert(){ var newli=document.createElement('div'); var randomS=Math.floor(Math.random()*8); var r=Math.floor(Math.random()*266); var g=Math.floor(Math.random()*266); var b=Math.floor(Math.random()*266); newli.innerHTML=speak[randomS]; newli.className='newli'; newli.style.color='rgb('+r+','+g+','+b+')'; var t=winH-50; var newliT=Math.floor(Math.random()*(t-1)); var newliL=danmu.clientWidth; newli.style.left=newliL+'px'; newli.style.top=newliT+'px'; danmu.appendChild(newli); move(newli); } function move(obj){ timer1=setInterval(function(){ // var danmu=document.getElementById('danmu'); var newliW=obj.clientWidth; var run=obj.offsetLeft; run--; if (run<=-newliW) { danmu.removeChild(obj); clearInterval(timer1); } obj.style.left=run+'px'; },1) } // insert(); var timer2=setInterval(function(){ insert(); },1000); window.onfocus=function (){ clearInterval(timer2); timer2=setInterval(function(){ Add(); },1000); } window.onblur=function (){ clearInterval(timer2); } </script> </body> </html>
查看完整描述

7 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

問題出在這一段:

timer1=setInterval(function(){
    //...
},1);

timer1是個全局變量,也就是每個對象都共享這個變量,肯定會沖突。

改成局部變量

var timer1

就好了,這樣每個對象就有了各自的定時器。

查看完整回答
反對 回復 2018-12-24
?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

?提示信息是不能刪除子節(jié)點,不知道是咋回事。。

查看完整回答
反對 回復 2018-12-24
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

var newli=document.createElement('div');

這個被設成局部變量了,在move()函數里不能被調用,把前面的var 去掉

查看完整回答
反對 回復 2018-12-24
?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

w我要連續(xù)定義很多個新節(jié)點,按你說的那樣雖然可以,但是效果就出不來了。

查看完整回答
反對 回復 2018-12-24
?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

@騎豬敲代碼: ?可以創(chuàng)建多個div啊,并不矛盾

查看完整回答
反對 回復 2018-12-24
?
holdtom

TA貢獻1805條經驗 獲得超10個贊

@一只求學喵: 那我試試去。。

查看完整回答
反對 回復 2018-12-24
  • 7 回答
  • 0 關注
  • 1670 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號