JQuery cancels subsequent execution. jquery cancels subsequent execution.
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript">
// Click the tag and the page is not redirected.
Window. onload = function (){
Var obj = document. getElementById ("myhref ");
Obj. onclick = function (event ){
// Cancel the default action
// Return false;
// Separate browsers
// Under IE
// 01. First capability Detection
Event = event | window. event;
If (event. preventDefault ){
// Non-IE
Event. preventDefault ();
} Else {
Event. returnValue = false;
}
};
}
</Script>
</Head>
<Body>
<A id = "myhref" href = "http://www.baidu.com"> go to Baidu </a>
</Body>
</Html>
Here, the click Effect of tag a is to jump to the Baidu page, but we can cancel the default behavior through parameters so that subsequent content of this click event will not be executed.
Sometimes there will be multiple events after clicking on the same tag. If you only want to execute the first event and discard the subsequent event, you can add a piece of code to prevent it:
<Span onclick = "alert ('will not be executed later! '); Event. stopPropagation (); "> click me! </Span>
How does jquery Block Post-bound events?
Your code has completed event binding during page loading. There is no way to block events that will be bound later. However, you can delete event binding for the current specified node. The method is as follows:
$ ("# Btn"). click (function (){
If ($ ("# tx"). val () = ""){
Alert ("e1 ");
} Else {
// Events bound after deletion...
$ ("# Btn"). unbind ('click ');
}
});
Note:
Unbind ([type], [data])
Bind () reverse operation to delete binding events from each matching element.
If no parameter exists, all bound events are deleted.
You can unbind the custom event you registered with bind.
If the event type is provided as a parameter, only binding events of this type are deleted.
If the handler passed during binding is used as the second parameter, only this specific event handler will be deleted.
Jquery: How can I block the second click event?
Jquery provides a method to trigger only one click.
Obj. one (function (){
});
Or you can use obj. unbind ("click") to cancel the click event.