Cancel the default action (response) of the browser on the event (for example, the jump of the <a> tag) and stop the event propagation.
Implementation Code
Copy codeThe 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)
Copy codeThe 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)
Copy codeThe Code is as follows:
Function stopEvent (evt ){
Var evt = evt | window. event;
If (evt. preventDefault ){
Evt. preventDefault ();
} Else {
Evt. returnValue = false;
}
}