Cancel the default action (response) of the browser on the event (for example, the jump of tag a) and stop the event from spreading, the following is a good example. You can cancel the browser's default event behavior (response) (such as tag jump) and stop the event propagation.
Implementation Code
The Code is as follows:
Function stopEvent (evt ){
Var evt = evt | window. event;
If (evt. preventDefault ){
Evt. preventDefault ();
Evt. stopPropagation ();
} Else {
Evt. returnValue = false;
Evt. cancelBubble = true;
}
}
Only prevent the event from spreading (do not cancel the default action)
The Code is as follows:
Function stopEvent (evt ){
Var evt = evt | window. event;
If (evt. stopPropagation ){
Evt. stopPropagation ();
} Else {
Evt. cancelBubble = true;
}
}
Only cancel the default action (do not stop the event from spreading)
The Code is as follows:
Function stopEvent (evt ){
Var evt = evt | window. event;
If (evt. preventDefault ){
Evt. preventDefault ();
} Else {
Evt. returnValue = false;
}
}