Jquery高级编程翻阅笔记5——jQuey事件处理
Jquery高级编程阅读笔记5——jQuey事件处理
-
使用jQuery进行事件处理
jQuery通过.bind()方法将一个函数绑定到一个事件。
.bind()
$("#objId").bind('mouseover',function(event){
});
.unbind()解除绑定
$("#objId").unbind("mouseover");
.on()
当DOM元素是动态插入的,这时候.bind()可能会失效,应该使用.on() 、.off()
.live()在1.9后删除了,代替为.on(),.on()统一了delegate(),.live(),.bind()功能,更加简洁
$("#anchor").on("click",function(){ alert(33); }) $("#content").append("<a id='anchor'>press me</a>")
.one()
实现一个事件处理程序只执行一次
链式调用
$(function(){ $("#text").mouseover(function(){ $(this).css("text-decoration","underline"); }).mouseout(function(){ $(this).css("text-decoration","none"); }) });