javascript - 1 单击 html 后禁用 href?

标签 javascript jquery html

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

相关文章:

javascript - 如何动态地将新列添加到 HTML 表

javascript - 使用 jquery 将 json 字符串与下拉列表绑定(bind)

jquery 工具错误 : Uncaught Error: Syntax error, 无法识别的表达式:[href=/]

html - CSS 设置高度和宽度,但在 flexbox 中调整 div 大小

HTML 验证 : Using element. validity.typeMismatch 和 element.validity.tooLong

javascript - 捕获Javascript中的图片特定错误

javascript - 如何在滚动时获取div的顶部位置值

javascript - 使用向上和向下箭头导航不起作用

javascript - 为什么这段 JavaScript 代码不起作用?

javascript - 检索发送者和接收者共享的消息 - chat mongodb, express, react