gpt4 book ai didi

javascript - 1 单击 html 后禁用 href?

转载 作者:太空狗 更新时间:2023-10-29 13:32:45 24 4
gpt4 key购买 nike

我希望在单击 1 次后禁用 href,可以使用 javascript 或 jquery 来完成吗?

请帮忙。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns ="http://www.w3.org 1999 xhtml" xml :lang="en">
<head>
<style>

a:link{
color:#1DAAA1;
}

a:visited{
color:green;
}

a:hover{
background: #ff0000;
color: #FFF;
}

</style>
</head>
<body>
<table width="500" align="center" border="5px solid">
<tr align="center" >
<td><a href="http://www.google.com.my/" onclick="return false"> Google </a></td>
<td><a href="http://www.yahoo.com/"> Yahoo </a></td>
<td><a href="http://www.bing.com/"> Bing </a></td>
<td><a href="http://en.wikipedia.org/wiki/Main_Page"> Wikipedia </a></td>
<td><a href="https://www.facebook.com/"> Facebook </a></td>
</tr>
</table>
</body>
</html>

最佳答案

纯javascript解决方案:

<script> 
function clickAndDisable(link) {
// disable subsequent clicks
link.onclick = function(event) {
event.preventDefault();
}
}
</script>
<a href="target.html" onclick="clickAndDisable(this);">Click here</a>

关于javascript - 1 单击 html 后禁用 href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13580815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com