第一种写法:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><script>//阻止超链接的默认的跳转:return false </script><a href="http://wwww.baidu.com" onclick="alert(‘哎呀,我被点了‘);return false">百度</a></body></html> 第二种写法:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><script> function f1(){ alert("哎呀,好漂亮啊!"); return false}//阻止超链接的默认的跳转:return false </script><a href="http://wwww.baidu.com" onclick="return f1()">百度</a></body></html>
第三种写法:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body> <a href="http://wwww.baidu.com" id=“ak”>百度</a><script> document.getElementById("ak").onclick = function(){ alert("哎呀,被点了"); return false;}</script></body></html>
原文地址:https://www.cnblogs.com/hcx123/p/10270904.html
时间: 2024-10-09 21:25:09