Aug
14
2009
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 เนี่ยแหละครับ
ตัวอย่าง
1 2 3 4 5 6 7 | <p>Click Here Test Event Bind</p> <script> $("p").bind("click",function(e){ alert("Bind onClick!!"); }); </script> |
หรือจะผูกกับ Events มากกว่า 1 Events ก็ได้นะครับ เช่นต้องการทั้ง onClick และ onMouseOver
1 2 3 | $("p").bind("click mouseover"function(e){ alert("Bind onClick and onMouseOver"); }); |
ง่ายใหมครับกับการผูก Event ต่างๆเข้าไปใน Tag ที่เราต้องการลองนำไปใช้กันดูครับ
Related Posts
Tags
.data
access iframe
advance
Ajax
attr
bind
browser
canvas
Core
debugs
Deferred
deferred.then
Deferred Object
delegate
DOM
Effect
event
Events
filters
google
HTML
html5
iframe
Image
jquery
jquery.data
jQuery 1.4
jquery 1.5
jQuery 1.6
jQuery 1.7
jquery mobile
jquery plugin
jquery ui
json
live
Plugin
plugins
selector
Selectors
show()
UI
undelegate
validate
welcome
what's jquery
Facebook Development
Google+ Page
Categories
- HTML5 & CSS3 (8)
- jQuery 1.4 (9)
- jQuery 1.5 (6)
- .data (1)
- jQuery 1.6 (3)
- .data (1)
- jQuery 1.7 (4)
- Events (1)
- jQuery Mobile (3)
- jQuery UI (3)
- Mobile (1)
- News (8)
- Others (28)
- Plugin (15)
- The basics of jQuery (9)
- Tips (13)
- คู่มือการใช้งาน jQuery ฉบับ ภาษา ไทย (30)
- Ajax (4)
- Attributes (1)
- Core (1)
- Deferred (3)
- Effects (7)
- Events (3)
- Manipulation (2)
- Selectors (5)
- Traversing (2)
- Utilities (2)

An article by







