Encountered a problem during actual development. Before making a click on the thumbnail to view a larger image.
Some users use old versions of IE browsers, or users turn off the JavaScript function.
If you rely entirely on js to achieve the effect, some users may not be able to use the website normally (there may be fewer and fewer such users).
One technology we need to use is non-obtrusive JavaScript.
If JS is not supported, the page will jump to another webpage
HTML code
But if you click the picture directly, it will jump to the web page specified by thetag.
If you want to prevent the jump, there are two methods below.
Method 1: Return a false
jQuery code
$('a').click(function(evt){ return false; });
Method 2: Use preventDefault() function
jQuery Code
$('a').click(function(evt){ evt.preventDefault(); });
The above two methods can effectively prevent link jumps.
It should be noted that in method one, the "return false;" statement must be the last line of the function, because once the JavaScript parser encounters the return statement, it will exit the function.
The above is the detailed content of How to stop link loading with jQuery. For more information, please follow other related articles on the PHP Chinese website!