事件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");
});
})