jquey中的事件绑定

三种方法:

$(selector).live(events, data, handler);                // jQuery 1.3+
$(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+
$(document).on(events, selector, data, handler);       // jQuery 1.7+
 
以上三种方法,data都是可选项;events参数可以为空格分开的list;
.live()不推荐使用,因为:1.(selector).live(),当文档很大时,selector耗时很严重
            2.不支持方法链(important)
            3.所有.live()事件都绑定在document上,处理之前经过的路径太长;
            4.iOS上的click事件,对大多元素不支持冒泡到document,如果不用如下解决方法的话,click事件不能使用:
                1)使用可单击元素如<a> <button>,因为这两个支持冒泡至document对象;
                2)针对比document.body更低级别的元素使用.on()或.delegate();
                3)针对需要冒泡click的元素运用CSS样式cursor:pointer;
 
使用.live()绑定多个事件,如下:
 
 1 $("p").live({
 2  click: function() {
 3     $(this).after("<p>Another paragraph!</p>");
 4   },
 5   mouseover: function() {
 6     $(this).addClass("over");
 7   },
 8   mouseout: function() {
 9     $(this).removeClass("over");
10   }
11 });
View Code
 
原文地址:https://www.cnblogs.com/paul-cheung/p/3191491.html