Browsing articles tagged with " Events"
Aug
14
2010

ถึงคราวของ jQuery .delegate() กันบ้างครับ

jquery delegate

วันนี้มาทำความรู้จักกับ Method Deledate กันบ้างครับซึ่ง Method หรือ Function นี้จะมีอยู่ใน jQuery 1.4 นะครับ ตามคำจำกัดความที่ทาง jQuery นั้นเขียนไว้ว่า “Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.” แปลเป็นไทยได้ทำนองนี้ครับ (แปลได้ งูๆปลาๆนะครับ – -’ ) jQuery delegate ก็คือ Function หรือ method ที่ใช้ในการ แทรก Event ต่างๆเข้าไปสามารถแทรกเข้ามาได้มากกว่า 1 event เช่น event Click, hover, mouseover, mouseout เป็นต้น ซึ่งจะแทรกเข้าไปในทุกๆ elements ที่ตรงกับที่เราได้ selector เอาไว้

Aug
14
2009

Events bind

มาทำความรู้จักกับ Event Bind กันบ้างครับ event bind นี้การทำงานของมันก็คือ การผูก event ต่างๆ เช่น blur, focus, load, resize, scroll, unload, beforeunload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, error ให้เข้าไปอยู่กับ element หรือ tag ต่างๆเช่นถ้าเราต้องการจะให้ tag P ให้มี event click แล้วให้ alert ค่าอะไรสักอย่างออกมาโดยที่เราไม่ต้องไปไล่ใส่ code onClick ใน tag นั้นๆ สามารถทำได้โดยการใช้ Bind เนี่ยแหละครับ ตัวอย่าง 1234567<p>Click Here Test Event Bind</p> <script>     $("p").bind("click",function(e){                 alert("Bind onClick!!"); [...]

Aug
14
2009

Events ready

วันนี้มาทำความรู้จักกับ Events ที่ชื่อว่า ready กันครับ Function Ready นั้นทำงานเหมือนกับ window.onload มันพิเศษตรงที่เราสามารถจับ Function อื่นๆให้ผูกกับ onload ได้ function ready นี้จะทำงานเมื่อ DOM ทำงาน มาดูตัวอย่างกันเลยยิ่งอ่านจะยิ่งงงไปกันใหญ่ 1234567$(document).ready(function(){ alert(’DOM ready!!’); }); // Result  : DOM ready!! เมื่อลองเอา code นี้ไปทดสอบดู จะเห็นได้ว่ามีการ alert ข้อความ DOM ready!! ออกมา เรามามารถนำ Function ไปใช้เมื่อต้องการให้โปรแกรมเราทำงานตั้งแต่การเปิด หรือ เรียก URL ขึ้นมาให้ทำงาน Javascript ที่ถูกผูกเข้ากับ Event นี้ก็จะเริ่มทำงานทันที