jQuery triggerHandler ()เมธอด
ตัวอย่าง
ทริกเกอร์เหตุการณ์ที่เลือกขององค์ประกอบ <input>:
$("button").click(function(){
$("input").triggerHandler("select");
});
ความหมายและการใช้งาน
เมธอด triggerHandler() ทริกเกอร์เหตุการณ์ที่ระบุสำหรับองค์ประกอบที่เลือก
เมธอดนี้คล้ายกับ เมธอด trigger() ยกเว้นว่า trigger() จะทริกเกอร์พฤติกรรมเริ่มต้นของเหตุการณ์ด้วย (เช่น การส่งแบบฟอร์ม)
ไวยากรณ์
$(selector).triggerHandler(event,param1,param2,...)
Parameter | Description |
---|---|
event | Required. Specifies the event to trigger for the specified element |
param1,param2,... | Optional. Additional parameters to pass on to the event handler. Additional parameters are especially useful with custom events |
ลองด้วยตัวคุณเอง - ตัวอย่าง
วิธีส่งต่อพารามิเตอร์เพิ่มเติมไปยังตัวจัดการเหตุการณ์ที่กำหนดเอง
แสดงให้เห็นถึงความแตกต่างระหว่าง trigger() และ triggerHandler()