Cancel subsequent executions in jquery

Source: Internet
Author: User

<title></title>
<script type= "Text/javascript" >
Click on the A tab without page jumps
Window.onload = function () {
var obj = document.getElementById ("Myhref");
Obj.onclick = function (event) {
Cancel default behavior
return false;
Sub-browser
IE under
01. First Capability Detection
Event = Event | | window.event;
if (Event.preventdefault) {

Non-IE under
Event.preventdefault ();
} else {
Event.returnvalue = false;
}
};
}
</script>
<body>
<a id= "Myhref" href= "http://www.baidu.com" > Go to Baidu </a>
</body>

The click effect of a tag here is originally to jump to the Baidu page, but we can remove the default behavior by the way the Click event will not be followed.

Sometimes you encounter multiple events on the same tab, and if you just want to execute the first event and discard the subsequent events, you can add a piece of code to block:

<span onclick= "alert (' the back will not be executed! '); Event.stoppropagation (); " >click me!</span>

How jquery blocks post-bound events

Your code has completed the event binding during page loading, there is no way to block post-bind events, but you can delete the event bindings for the currently specified node. Here's how:
$ ("#btn"). Click (function () {
if ($ ("#tx"). val () = = "") {
Alert ("E1");
}else{
After you delete the bound event ...
$ ("#btn"). Unbind (' click ');
}
});

Description
Unbind ([Type],[data])
The reverse operation of BIND () removes the bound event from each matching element.
If there are no parameters, all bound events are deleted.

You can unbind a custom event that you have registered with bind ().

If the event type is provided as a parameter, only the binding event of that type is deleted.

If you pass a handler function that is passed at bind time as the second argument, only that particular event handler will be deleted.

jquery: How can I prevent the second click event?

jquery provides a way to trigger only one click
Obj.one (function () {

});
or cancel the Click event with Obj.unbind ("click")

Cancel subsequent executions in jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.