This article introduces the use of jquery removeattr and attr events to give a label to increase and delete the OnClick event of the specific operation method, there is a need to understand friends can refer.
To achieve effect: Click on the link to remove the OnClick property, 3 seconds and then automatically add the onclick attribute in the label
In jquery, actions for label properties are implemented using the attr () method, such as: $ ("a"). attr ("onclick") gets the OnClick property of a label, corresponding to:
Increase Event
$ (selector). attr (property name) its role is to get the value of the specified property for the specified element (the $ (selector) portion)
such as setting the OnClick property: $ ("a"). attr ("onclick", "Test ();");
Delete Event
$ (selector). Removeattr (attribute)
For example, delete the onclick attribute: $ ("a"). Removeattr ("onclick");
Theoretically the above code is fine, but in fact the above statement does not execute or error, and later found the reason:
The previous version of JQuery 1.6 does not support the attr () method for the label OnClick property.
In other words, to use the attr () method to manipulate the OnClick property in the tag, you must use the JQ library 1.6 or the updated library version.
<script type= "Text/javascript" src= "jquery.min.js" ></script><script type= "Text/javascript" >
$ (function () {
$ (". B"). Click (function () {
$ (this). Removeattr ("onclick");
settimeout (function () {
$ (". B"). attr ("onclick", "Test ();");
},3000)}
})
function Test () {}
</script>
<p>
<a class= "B" href= "# onclick=" Test (); " > Click to remove the onclick attribute of the link, and then automatically add the OnClick property after 3 seconds </a>
</p>
The key word for deleting attributes in jquery is: removeattr Note that A is uppercase
jquery also has a way to disarm event delegates: Unbind ([EventType]). parameter is optional and, if not selected, represents the removal of all bound events for the node.
Here you just need to dismiss the Click event, which can be handled with $ ("#s1"). Unbind ("click").