jQuery delegate() နည်းလမ်း
ဥပမာ
<p> ဒြပ်စင်တစ်ခုအတွင်းရှိ <div> ဒြပ်စင်တစ်ခုကို နှိပ်လိုက်သောအခါ၊ <p> ဒြပ်စင်အားလုံး၏ နောက်ခံအရောင်ကို ပြောင်းပါ-
$("div").delegate("p", "click", function(){
$("p").css("background-color", "pink");
});
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
delegate() နည်းလမ်းကို ဗားရှင်း 3.0 တွင် ငြင်းပယ်ထားသည်။ ၎င်း အစား on() method ကိုသုံးပါ။
delegate() နည်းလမ်းသည် ရွေးချယ်ထားသော ဒြပ်စင်များ၏ ကလေးများဖြစ်သည့် သတ်မှတ်ထားသော ဒြပ်စင်များအတွက် တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော event handlers ကို ပူးတွဲပြီး ဖြစ်ရပ်များ ဖြစ်ပေါ်လာသည့်အခါ လုပ်ဆောင်ရန် လုပ်ဆောင်ချက်ကို သတ်မှတ်ပေးပါသည်။
delegate() နည်းလမ်းကို အသုံးပြု၍ ပူးတွဲပါ အစီအစဉ် ကိုင်တွယ်သူများသည် လက်ရှိ နှင့် အနာဂတ် ဒြပ်စင် (script တစ်ခုမှ ဖန်တီးထားသော ဒြပ်စင်အသစ်ကဲ့သို့) အတွက် အလုပ်လုပ်ပါမည်။
အထားအသို
$(selector).delegate(childSelector,event,data,function)
Parameter | Description |
---|---|
childSelector | Required. Specifies one or more child elements to attach the event handler to |
event | Required. Specifies one or more events to attach to the elements. Multiple event values are separated by space. Must be a valid event |
data | Optional. Specifies additional data to pass along to the function |
function | Required. Specifies the function to run when the event occurs |
သင်ကိုယ်တိုင်စမ်းကြည့်ပါ - ဥပမာများ
မဖန်တီးရသေးသောဒြပ်စင်များအတွက် event handlers များထည့်ရန် delegate() method ကိုအသုံးပြုနည်း
စိတ်ကြိုက်အမည်ပေးထားသည့် ဖြစ်ရပ်ကိုင်တွယ်သူထံ ဒေတာတစ်လျှောက် ဖြတ်သန်းနည်း။