The example in this article describes how JavaScript handles the default event of a tag hyperlink. Share it with everyone for your reference. The specific analysis is as follows:
Sometimes it is necessary to add a click event to the a tag and handle some transactions before jumping, so some processing needs to be done; usually the front end will give a link to represent For this behavior, some people will write it like link or link , but this is not compatible with all browsers, and some browsers will behave strangely.
Therefore, this problem requires other methods to solve. One is to use jquery to block the default event, just like the example given in JQUERY's official API:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>event.preventDefault demo</title> <script src="jquery-1.10.2.js"></script> </head> <body> <a href="http://jquery.com">default click action is prevented</a> <div id="log"></div> <script> $( "a" ).click(function( event ) { event.preventDefault(); $( "<div>" ) .append( "default " + event.type + " prevented" ) .appendTo( "#log" ); }); </script> </body> </html>
Another method is to add a javascript method to the hyperlink, and add return to the method
I hope this article will be helpful to everyone’s JavaScript programming design.