This article illustrates how jquery uses namespaces to remove binding events. Share to everyone for your reference. The specific analysis is as follows:
A recent study of jquery found a simple way to remove binding events, namespaces.
The example is simple.
Here I've bound three events, the Click,mouseover and DblClick events, respectively.
Where the click and MouseOver events I joined the namespace, and DblClick did not join the namespace.
A button is used to remove the bound event.
This avoids the repeated use of the bind and Unbind methods to make your code look simpler and clearer.
Copy Code code as follows:
<script type= "Text/javascript" src= "Js/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$ ("div"). Bind ("Click.plugin", function () {
$ ("Body"). Append ("<p>click event </p>");
});
$ ("div"). Bind ("Mouseover.plugin", function () {
$ ("Body"). Append ("<p>mouseover event </p>");
});
$ ("div"). Bind ("DblClick", function () {
$ ("Body"). Append ("<p>dblclick event </p>");
});
$ ("#but"). Click (function () {
Alert ("Remove");
$ ("div"). Unbind (". Plugin");
});
})
</script>
<div style= "border:1px solid red;height:100px;width:300px;" > has already bound the layer </div> of the <br/>click,mouseover,dblclick event
<input id= "But" type= "button" value= "Remove" ></input>
The operation effect is as follows:
I hope this article will help you with your jquery programming.