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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

style.marginLeft 報(bào)錯(cuò)Cannot read property 'style' of undefined

var marginLeft = parseInt(ball.style.marginLeft,10)?

這行報(bào)錯(cuò),Cannot read property 'style' of undefined?

是不是style.marginLeft這個(gè)寫法有問(wèn)題呢?


正在回答

5 回答

要把_animate()里面的參數(shù)刪了,因?yàn)槟阍谶@個(gè)函數(shù)外面以及有個(gè)ball了。

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

一仁 提問(wèn)者

確實(shí)是的啊,非常感謝!
2016-07-26 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕粉1657331796

完美解決了問(wèn)題!
2017-06-17 回復(fù) 有任何疑惑可以回復(fù)我~

如果你問(wèn)的是promise改寫之前的話,是因?yàn)槟愕腷ody還沒(méi)加載就加載了js, 所以提示undefined

0 回復(fù) 有任何疑惑可以回復(fù)我~

var Promise = window.Promise
function promiseAnimate(ball,distance){
? ?return new Promise(function(resolve,reject){
? ? ? ?function _animate(ball,distance,cb){
? ? ? ? ? ?setTimeout(function () {
? ? ? ? ? ? ? ?var marginLeft = parseInt(ball.style.marginLeft,10)

? ? ? ? ? ? ? ?if(marginLeft === distance){
? ? ? ? ? ? ? ? ? ?resolve()
? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ?if(marginLeft < distance){
? ? ? ? ? ? ? ? ? ? ? ?marginLeft++
? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ?marginLeft--
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?ball.style.marginLeft = marginLeft + 'px'
? ? ? ? ? ? ? ? ? ?_animate()
? ? ? ? ? ? ? ?}
? ? ? ? ? ?},13)
? ? ? ?}
? ? ? ?_animate()
? ?})
}

0 回復(fù) 有任何疑惑可以回復(fù)我~

一般通過(guò)非id和querySelect獲得的dom元素都是一個(gè)數(shù)組,要加下標(biāo)比如ball[0]來(lái)調(diào)用對(duì)象的屬性

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

_boom

querySelector() 方法返回文檔中匹配指定 CSS 選擇器的一個(gè)元素。 注意: querySelector() 方法僅僅返回匹配指定選擇器的第一個(gè)元素。如果你需要返回所有的元素,請(qǐng)使用 querySelectorAll() 方法替代。
2016-07-26 回復(fù) 有任何疑惑可以回復(fù)我~

你看一下你的ball是不是個(gè)數(shù)組

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

一仁 提問(wèn)者

不是數(shù)組,我對(duì)比了下老師的代碼,三個(gè)球的class都是ball,函數(shù)傳入了ball,距離和回調(diào)函數(shù),一樣的,不知是何原因
2016-07-24 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
進(jìn)擊Node.js基礎(chǔ)(二)
  • 參與學(xué)習(xí)       76728    人
  • 解答問(wèn)題       242    個(gè)

本教程帶你攻破 Nodejs,讓 JavaScript流暢運(yùn)行在服務(wù)器端

進(jìn)入課程

style.marginLeft 報(bào)錯(cuò)Cannot read property 'style' of undefined

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)