jQuery on() နည်းလမ်း
ဥပမာ
ကလစ်ဖြစ်ရပ်ကို <p> ဒြပ်စင်သို့ ပူးတွဲပါ-
$("p").on("click", function(){
alert("The paragraph was clicked.");
});
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
on() နည်းလမ်းသည် ရွေးချယ်ထားသော ဒြပ်စင်များနှင့် ကလေးဒြပ်စင်များအတွက် တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော ဖြစ်ရပ်ကိုင်တွယ်သူများကို ပူးတွဲထားသည်။
jQuery ဗားရှင်း 1.7 အရ၊ on() နည်းလမ်းသည် bind(), live() နှင့် delegate() နည်းလမ်းများအတွက် အစားထိုးမှုအသစ်ဖြစ်သည်။ ဤနည်းလမ်းသည် API ဆီသို့ လိုက်လျောညီထွေမှုများစွာကို ယူဆောင်လာပြီး jQuery ကုဒ်အခြေခံကို ရိုးရှင်းစေသောကြောင့် ဤနည်းလမ်းကို အသုံးပြုရန် အကြံပြုအပ်ပါသည်။
မှတ်ချက်- on() နည်းလမ်းကို အသုံးပြု၍ ပူးတွဲထားသော အစီအစဉ်ကိုင်တွယ်သူများသည် လက်ရှိနှင့် အနာဂတ် ဒြပ်စင်များ (ဇာတ်ညွှန်းတစ်ခုမှ ဖန်တီးထားသည့် ဒြပ်စင်အသစ်ကဲ့သို့) နှစ်ခုလုံးအတွက် အလုပ်လုပ်မည်ဖြစ်သည်။
အကြံပြုချက်- ဖြစ်ရပ်ကိုင်တွယ်သူများကို ဖယ်ရှားရန်၊ off() နည်းလမ်းကို အသုံးပြုပါ။
အကြံပြုချက်- တစ်ကြိမ်သာ လုပ်ဆောင်ပြီး ၎င်းကိုယ်တိုင် ဖယ်ရှားသည့် ဖြစ်ရပ်တစ်ခုကို ပူးတွဲဆောင်ရွက်ရန် one() နည်းလမ်းကို အသုံးပြုပါ။
အထားအသို
$(selector).on(event,childSelector,data,function,map)
Parameter | Description |
---|---|
event | Required. Specifies one or more event(s) or namespaces to attach to the selected elements. Multiple event values are separated by space. Must be a valid event |
childSelector | Optional. Specifies that the event handler should only be attached to the specified child elements (and not the selector itself, like the deprecated delegate() method). |
data | Optional. Specifies additional data to pass along to the function |
function | Required. Specifies the function to run when the event occurs |
map | Specifies an event map ({event:function, event:function, ...}) containing one or more event to attach to the selected elements, and functions to run when the events occur |
သင်ကိုယ်တိုင်စမ်းကြည့်ပါ - ဥပမာများ
များစွာကို ပူးတွဲပါ အကြောင်းအရာတစ်ခုသို့ ဖြစ်ရပ်များစွာကို တွဲနည်း။
သူအများအပြားကို ပူးတွဲပါ မြေပုံပါရာမီတာကို အသုံးပြု၍ ရွေးချယ်ထားသော အစိတ်အပိုင်းများသို့ ဖြစ်ရပ်ကိုင်တွယ်သူအများအပြားကို ချိတ်ဆက်နည်း။
ပေါ်တွင် စိတ်ကြိုက် namespace ဖြစ်ရပ်တစ်ခုကို ပူးတွဲနည်း။
သို့ ဖြတ်သန်းရန် ဒေတာကို လုပ်ဆောင်ချက်သို့ မည်ကဲ့သို့ ဖြတ်သန်းမည်နည်း။
on() method သည် မဖန်တီးရသေးသော element များအတွက်လည်း အဆင်ပြေကြောင်းပြပါ။
off() method ကို အသုံးပြု၍ event handler ကို ဖယ်ရှားနည်း