任何人都可以告訴我爲什麼下面的代碼似乎無法阻止鏈接做它的事情?我知道我可以使用onclick="return false"
,但它應該與preventDefault一起使用,對吧?我試過onclick="function(e){this.preventDefault()}"
和onclick="this.preventDefault()"
,但沒有愛。在onclick中使用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>
我會說,這取決於瀏覽器:) –