JavaScript DHTML/jQuery/unbind
Содержание
To unbind all click events from all paragraphs
<source lang="html4strict">
$("p").unbind( "click" )
</source>
To unbind just one previously bound handler, pass the function in as the second argument:
<source lang="html4strict">
var foo = function () {
// event handler
}; $("p").bind("click", foo); // foo is binded $("p").unbind("click", foo); // foo is no longer binded
</source>
Unbind all events from
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("div").unbind() }); </script>
</head> <body> <body>
header 1
</body>
</html>
</source>
Unbind all live events from all paragraphs
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("div").die();
}); </script>
</head> <body> <body>
header 1
</body>
</html>
</source>
Unbind event
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ function aClick() { $("div").show().fadeOut("slow"); } $("div").click(function () { $("div").unbind("click", aClick).text("Does nothing..."); });
}); </script>
</head> <body> <body>
header 1
</body>
</html>
</source>
unbind(type , data ): Without any arguments, all bound events are removed.
<source lang="html4strict">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ function aClick() { alert("action"); } $("#bind").click(function () { $("#myButton").click(aClick).text("Binded"); }); $("#unbind").click(function () { $("#myButton").unbind("click", aClick).text("Not Binded"); }); }); </script> </head> <body> <body> <button id="myButton">Not Binded</button> <button id="bind">Bind Click</button> <button id="unbind">Unbind Click</button> </body>
</html>
</source>