jQuery ผูก ()วิธีการ

❮ วิธีการจัดกิจกรรม jQuery

ตัวอย่าง

แนบเหตุการณ์คลิกกับ <p> องค์ประกอบ:

$("p").bind("click", function(){
  alert("The paragraph was clicked.");
});

ความหมายและการใช้งาน

วิธี bind() เลิกใช้แล้วในเวอร์ชัน 3.0 ใช้วิธี on()แทน

 วิธี bind() แนบตัวจัดการเหตุการณ์ตั้งแต่หนึ่งตัวขึ้นไปสำหรับองค์ประกอบที่เลือก และระบุฟังก์ชันที่จะเรียกใช้เมื่อเกิดเหตุการณ์


ไวยากรณ์

$(selector).bind(event,data,function,map)

Parameter Description
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
map Specifies an event map ({event:function, event:function, ...}) containing one or more events to attach to the elements, and functions to run when the event occurs

ลองด้วยตัวคุณเอง - ตัวอย่าง


วิธีแนบหลายเหตุการณ์กับองค์ประกอบ


วิธีใช้แผนผังเหตุการณ์เพื่อแนบเหตุการณ์/ฟังก์ชันต่างๆ กับองค์ประกอบที่เลือก


วิธีส่งต่อข้อมูลไปยังตัวจัดการเหตุการณ์ที่มีชื่อแบบกำหนดเอง


❮ วิธีการจัดกิจกรรม jQuery