<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