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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

關(guān)于n的次數(shù)問題 ???? var n = 0; //綁定事件 $(".aaron:last").on('mousedown mouseup', function(e) { $(this).text( '觸發(fā)類型:' + (e.type) + ",次數(shù)" + ++n) ++n; })

為什么點(diǎn)擊后松開 n是3而不是2???

當(dāng)我寫這樣的時候,顯示的n的結(jié)果是2

$(this).text( '觸發(fā)類型:' + ?(e.type) + ",次數(shù)" + ++n)


老師的源碼寫這樣的時候,顯示的n的結(jié)果是3。結(jié)尾多了++n 是想說明什么?

?$(this).text( '觸發(fā)類型:' + ?(e.type) + ",次數(shù)" + ++n)?++n;


<h4>測試一</h4>

? ? <div class="left">?

? ? ? ? on('mousedown mouseup')

? ? ? ? <div class="aaron">點(diǎn)擊觸發(fā)</div>

? ? </div>

? ? <button>點(diǎn)擊銷毀所有事件off</button>

? ? <script type="text/javascript">

? ? var n ?= 0;

? ? //綁定事件

? ? $(".aaron:last").on('mousedown mouseup', function(e) {

? ? ? ? $(this).text( '觸發(fā)類型:' + ?(e.type) + ",次數(shù)" + ++n)

? ? ? ? ++n;

? ? })


? ? //刪除事件

? ? $("button:last").click(function() {

? ? ? ? $(".aaron:last").off()

? ? })

? ?

? ? </script>


正在回答

3 回答

你的順序有些問題,先是n==1,顯示,然后n==2,這都是mousedown事件的執(zhí)行過程。

$(this).text( '觸發(fā)類型:' + ?(e.type) + ",次數(shù)" + ++n)

? ? ? ? ++n;

仔細(xì)看你的源碼,你再++n一次之后就輸出了,所以在顯示了1之后mousedown事件還沒有結(jié)束,會接著執(zhí)行++n;之后才會結(jié)束,這時候n==2。之后你松開了鼠標(biāo)觸發(fā)了mouseup事件。這時也是先執(zhí)行$(this).text( '觸發(fā)類型:' + ?(e.type) + ",次數(shù)" + ++n)這句。所以顯示的是(在n==2之后)++n的值也就是3。之后執(zhí)行++n;n==4結(jié)束mouseup事件。


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

淡水狗 提問者

非常感謝!
2017-07-17 回復(fù) 有任何疑惑可以回復(fù)我~
#2

沫荼 回復(fù) 淡水狗 提問者

你看明白了就好
2017-07-17 回復(fù) 有任何疑惑可以回復(fù)我~

先是n==0,不是1

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

當(dāng)你按下鼠標(biāo)時觸發(fā)mousedown,++n,n==1,顯示1,之后++n,n==2,松開鼠標(biāo)時觸發(fā)mouseup,++n,n==3,顯示3,之后++n,n==4.

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

淡水狗 提問者

當(dāng)按下鼠標(biāo)時觸發(fā)mousedown,++n,n==1,顯示1這個能理解,那 $(this).text( '觸發(fā)類型:' + (e.type) + ",次數(shù)" + ++n)++n; n==2是因?yàn)槔ㄌ杻?nèi)的n==1了再加上括號外面的++n 等于2是嗎? 如果是這樣的話那松開時 n==3加上外面的++n 不就等于4嗎? 怎么一開始還是顯示3?
2017-07-17 回復(fù) 有任何疑惑可以回復(fù)我~
#2

沫荼 回復(fù) 淡水狗 提問者

字?jǐn)?shù)限制我寫下面了
2017-07-17 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

關(guān)于n的次數(shù)問題 ???? var n = 0; //綁定事件 $(".aaron:last").on('mousedown mouseup', function(e) { $(this).text( '觸發(fā)類型:' + (e.type) + ",次數(shù)" + ++n) ++n; })

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

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

幫助反饋 APP下載

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

公眾號

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