jQuery Misc data() နည်းလမ်း
ဥပမာ
ဒေတာကို <div> ဒြပ်စင်တစ်ခုသို့ ပူးတွဲပါ၊ ထို့နောက် ဒေတာကို ရယူပါ-
$("#btn1").click(function(){
$("div").data("greeting", "Hello World");
});
$("#btn2").click(function(){
alert($("div").data("greeting"));
});
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
data() method သည် ဒေတာကို ချိတ်ဆက်ပေးသည်၊ သို့မဟုတ် ရွေးချယ်ထားသော အစိတ်အပိုင်းများမှ ဒေတာကို ရယူသည်။
အကြံပြုချက်- ဒေတာကို ဖယ်ရှားရန်၊ removeData() နည်းလမ်းကို အသုံးပြုပါ။
Element တစ်ခုမှ ဒေတာကို ပြန်ပို့ပါ။
ရွေးထားသည့်အရာမှ ပူးတွဲပါဒေတာကို ပြန်ပေးသည်။
အထားအသို
$(selector).data(name)
Parameter | Description |
---|---|
name | Optional. Specifies the name of data to retrieve. If no name is specified, this method will return all stored data for the element as an object |
ဒေတာကို Element တစ်ခုသို့ ပူးတွဲပါ။
ရွေးချယ်ထားသော အစိတ်အပိုင်းများသို့ ဒေတာကို ပူးတွဲပါ။
အထားအသို
$(selector).data(name,value)
Parameter | Description |
---|---|
name | Required. Specifies the name of data to set |
value | Required. Specifies the value of data to set |
အရာဝတ္တုကို အသုံးပြု၍ ဒြပ်စင်တစ်ခုသို့ ဒေတာကို ပူးတွဲပါ။
အမည်/တန်ဖိုးအတွဲများပါသည့် အရာဝတ္ထုကို အသုံးပြု၍ ရွေးချယ်ထားသော ဒြပ်စင်များသို့ ဒေတာကို ပူးတွဲပါ။
အထားအသို
$(selector).data(object)
Parameter | Description |
---|---|
object | Required. Specifies an object containing name/value pairs |