jQuery off() နည်းလမ်း
ဥပမာ
<p> အစိတ်အပိုင်းအားလုံးအတွက် ကလစ်ဖြစ်ရပ်ကို ဖယ်ရှားပါ-
$("button").click(function(){
$("p").off("click");
});
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
off() method ကို on() method ဖြင့် ပူးတွဲပါရှိသော event handlers များကို ဖယ်ရှားရန် မကြာခဏ အသုံးပြု ပါသည်။
jQuery ဗားရှင်း 1.7 အရ၊ off() နည်းလမ်းသည် unbind(), die() နှင့် undelegate() နည်းလမ်းများအတွက် အစားထိုးမှုအသစ်ဖြစ်သည်။ ဤနည်းလမ်းသည် API ဆီသို့ လိုက်လျောညီထွေမှုများစွာကို ယူဆောင်လာပြီး jQuery ကုဒ်အခြေခံကို ရိုးရှင်းစေသောကြောင့် ဤနည်းလမ်းကို အသုံးပြုရန် အကြံပြုအပ်ပါသည်။
မှတ်ချက်- သတ်သတ်မှတ်မှတ် event handlers များကို ဖယ်ရှားရန်၊ event handler ကို တွဲထားသောအခါတွင် ရွေးပေးသည့်စာကြောင်းသည် on() method သို့ ပေးပို့ထားသည့်အရာနှင့် ကိုက်ညီရပါမည်။
အကြံပြုချက်- တစ်ကြိမ်သာ လုပ်ဆောင်ပြီး ၎င်းကိုယ်တိုင် ဖယ်ရှားသည့် ဖြစ်ရပ်တစ်ခုကို ပူးတွဲဆောင်ရွက်ရန် one() နည်းလမ်းကို အသုံးပြုပါ။
အထားအသို
$(selector).off(event,selector,function(eventObj),map)
Parameter | Description |
---|---|
event | Required. Specifies one or more events or namespaces to remove from the selected element(s). Multiple event values are separated by a space. Must be a valid event |
selector | Optional. A selector which should match the one originally passed to the on() method when attaching event handlers |
function(eventObj) | Optional. 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 elements, and functions to run when the events occur |
သင်ကိုယ်တိုင်စမ်းကြည့်ပါ - ဥပမာများ
on() နည်းလမ်းဖြင့် ထည့်သွင်းထားသော <p> အစိတ်အပိုင်းအားလုံးအတွက် ကလစ်ဖြစ်ရပ်ကိုင်တွယ်သူအားလုံးကို ဖယ်ရှားနည်း၊
အား ဖယ်ရှားနည်း on() နည်းလမ်းဖြင့် ထည့်သွင်းထားသော သီးခြားလုပ်ဆောင်ချက်ကို ဖယ်ရှားနည်း။
အဖြစ်အပျက်ကို အကြိမ်ပေါင်းများစွာ အစပျိုးပြီးနောက် ဖြစ်ရပ်ကိုင်တွယ်သူအား