任何人都可以告诉我为什么下面的代码似乎没有阻止链接做它的事情?我知道我可以使用onclick="return false",但它应该与preventDefault一起使用,对吧?我试过onclick="function(e){this.preventDefault()}"和onclick="this.preventDefault()",但没有爱.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<a href="http://www.google.com" onclick="function(e){e.preventDefault()}">Google Search</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) javascript ×1