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