最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

$.data($(this),'key1',"name");為什么這么寫(xiě)不行的,而是要賦值?

?$(".left").click(function(){

? ? ? ? ? ?//給rleft增加數(shù)據(jù)存儲(chǔ)

? ? ? ? ? ? $.data($(this),'key1',"name");

? ? ? ? ? ? //獲取數(shù)據(jù)

? ? ? ? ? ? var text = $.data($(this),"key1");

? ? ? ? ? ? $("span").text(text);

? ? ? ? })

為什么這么寫(xiě)沒(méi)內(nèi)容輸出,而是要賦值?

div>

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

? ? ? ? $(".left").click(function(){

? ? ? ? ? ?var ?$this = $(this);

? ? ? ? ? ?//給rleft增加數(shù)據(jù)存儲(chǔ)

? ? ? ? ? ? $.data($this,'key1',"name");

? ? ? ? ? ? //獲取數(shù)據(jù)

? ? ? ? ? ? var text = $.data($this,"key1");

? ? ? ? ? ? $("span").text(text);

? ? ? ? })

? ? </script>


正在回答

2 回答

?$(".left").click(function(){
???????????//給rleft增加數(shù)據(jù)存儲(chǔ)
????????????$.data($(this),'key1',"name");
????????????//獲取數(shù)據(jù)
????????????var?text?=?$.data($(this),"key1");
????????????$("span").text(text);
????????})

關(guān)鍵字 this 總是指向調(diào)用該方法的對(duì)象

第一個(gè)this是指.left這個(gè)節(jié)點(diǎn)

第二個(gè)this是指$.data($(this),'key1',"name");

this是不斷變化的,必須用變量存儲(chǔ)起來(lái)

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

文醬醬 提問(wèn)者

非常感謝!
2017-03-10 回復(fù) 有任何疑惑可以回復(fù)我~

$.data($(this), "a", "data test");這句話(huà)里的$(this)應(yīng)該代表的是$,也就是jQuery,而不是?$(".left")這個(gè)元素.

$('.right').click(function() {
? ?var ele = $(this);
? ?//通過(guò).data方式設(shè)置數(shù)據(jù)
? ?$(this).data("a", "data test")
? ?$(this).data("b", {
? ? ? ?name: "慕課網(wǎng)"
? ?})
? ?//通過(guò).data方式取出數(shù)據(jù)
? ?var reset = $(this).data("a") + "</br>" + $(this).data("b").name
? ?ele.find('span').append(reset)
})

這個(gè)里面的$(this)指的就是$('.right')這個(gè)個(gè)元素,?$(this).data("a", "data test")數(shù)據(jù)也是存儲(chǔ)在它下面的的。

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

舉報(bào)

0/150
提交
取消

$.data($(this),'key1',"name");為什么這么寫(xiě)不行的,而是要賦值?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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