`
Folix
  • 浏览: 12202 次
社区版块
存档分类
最新评论

Jquery高级编程阅读笔记5——jQuey事件处理

阅读更多
  1. 使用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");
    	})
    });
     
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics