事件javascript
(*)JQuery中的事件绑定:$(“#btn”).bind(“click”,function(){}),每次都这么调用太麻烦,因此jQuery能够用$(“#btn”).click(function(){})来进行简化。unbindhtml
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="Jqeury/jquery-1.10.2.js"></script> <script type="text/javascript"> $(function () { $("input[value='bind']").click(function() { $("#btn").bind( { "click": function() { alert("click"); }, "mouseover": function() { alert("mouseover"); }, "mouseout": function() { alert("mouseout"); } } ); }); $("input[value='unbind']").click(function () { //移除事件 //$("#btn").unbind("mouseout"); //移除全部事件 $("#btn").unbind(); }) }) </script> </head> <body> <input id="btn" type="button" value="test"> <input type="button" value="bind"> <input type="button" value="unbind"> <input type="button" value="one" /> </body> </html>
一次性事件:若是绑定的事件只想执行一次随后当即unbind能够使用one()方法进行事件绑定 java
//一次性事件
$("input[value='one']").click(function () {
$("#btn").one("click", function() {
alert("click");
});
})