我希望在单击 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/