如何在单击后禁用链接 [英] How do I disable a link after it clicked

查看:133
本文介绍了如何在单击后禁用链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I tried document.getElementById("link1").disabled = true; but its did't work...so please help..





我尝试过的事情:



我试过document.getElementById(link1)。disabled = true;但它没有用......所以请帮助..



What I have tried:

I tried document.getElementById("link1").disabled = true; but its did't work...so please help..

推荐答案

假设您的链接位于< div>内。包装。现在,当您的onclick事件被触发时,您将禁用< div>,这会禁用其所有内容。或者你甚至可以隐藏div(以及它的内容)。



您的代码示例有点稀疏。




评论中的每次更正:如何禁用链接CSS-Tricks [ ^ ]解决问题。
Suppose your link were inside of a <div> wrapper. Now, when your onclick event is triggered you disable the <div>, which disables all of its content. Or you could even hide the div (and thus its content).

You code sample is a little sparse.


Per correction in comment: How to Disable Links | CSS-Tricks[^] address the question.


禁用的原因很可能不起作用,因为它不是< a>的有效属性。元件。它仅适用于您通常在表单中找到的元素。

W3 Schools>已停用的属性 [ ^ ]



我想尝试的是在点击时从链接中删除href属性。
The reason "disabled" most likely did not work is that it is not a valid attribute for a <a> element. It only works on elements you would normally find within a form.
W3 Schools > disabled attribute[^]

What I would try would be to remove the href attribute from the link when clicked.


这篇关于如何在单击后禁用链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆