事件绑定
1、简单事件绑定:$("button").click(function () {}),重复绑定,不会被层叠
2、bind():$("button").bind("click mouseenter",function () {}),可通过绑定多个事件,但是事件源必须存在文档中,不推荐使用
3、delegate():$(".parentBox").delegate("p", "click", function(){}) 或者 $("button").delegate("click",function () {}),支持动态创建元素
4、on():$(.parentBox).on( "click",“span”, function() {}) 或者 $(selector).on(events[,selector][,data],handler) 或者 $("button").on("click",function () {})
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title>Title</title> ???<style> ???????div { ???????????width: 100px; ???????????height: 100px; ???????????border: 1px solid #ccc; ???????} ???</style> ???<script src="jquery-1.11.1.js"></script> ???<script> ???????$(function () { ???????????$("div").on("click", "button:eq(0)", function () { ???????????????alert("11"); ???????????}); ???????????$("button:eq(1)").on("click", function () { ???????????????alert(22); ???????????}); ???????}); ???</script></head><body><div> ???<button>点击1</button> ???<button>点击2</button></div></body></html>
事件解绑
jQuery——事件操作
原文地址:http://www.cnblogs.com/wuqiuxue/p/8039017.html