JavaScript Tutorial/jQuery/unbind — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:25, 26 мая 2010
Содержание
30. To unbind all click events from all paragraphs
<source lang="javascript">
$("p").unbind( "click" )</source>
30. To unbind just one previously bound handler, pass the function in as the second argument:
<source lang="javascript">
var foo = function () {
// event handler
}; $("p").bind("click", foo); // foo is binded $("p").unbind("click", foo); // foo is no longer binded</source>
30. Unbind all events from
<source lang="javascript">
<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>
30. Unbind all live events from all paragraphs
<source lang="javascript">
<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>
30. Unbind event
<source lang="javascript">
<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>
30. unbind(type , data ): Without any arguments, all bound events are removed.
<source lang="javascript">
<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>