Javascript 禁用的 href 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13955667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disabled href tag
提问by Alan Coromano
Although that link is disabled, it's still clickable.
尽管该链接已禁用,但它仍然可以点击。
<a href="/" disabled="disabled">123n</a>
Can I make it not-clickable if it's disabled? Should I use JavaScript necessarily?
如果它被禁用,我可以让它不可点击吗?我一定要使用 JavaScript 吗?
采纳答案by John Conde
There is no disabled attribute for hyperlinks. If you don't want something to be linked then you'll need to remove the <a>tag altogether, or remove its hrefattribute.
超链接没有禁用属性。如果您不想链接某些内容,则需要<a>完全删除标记,或删除其href属性。
回答by Lakhan
With the help of css you will disable the hyperlink. Try the below
在 css 的帮助下,您将禁用超链接。试试下面的
a.disabled {
pointer-events: none;
cursor: default;
}
<a href="link.html" class="disabled">Link</a>
回答by CodeLikeBeaker
You can use:
您可以使用:
<a href="/" onclick="return false;">123n</a>
回答by IgniteCoders
You can use one of these solutions:
您可以使用以下解决方案之一:
HTML
HTML
<a>link</a>
JavaScript
JavaScript
<a href="javascript:function() { return false; }">link</a>
<a href="/" onclick="return false;">link</a>
CSS
CSS
<a href="www.page.com" disabled="disabled">link</a>
<style type="text/css">
a[disabled="disabled"] {
pointer-events: none;
}
</style>
回答by IgniteCoders
Try this:
尝试这个:
<a href="javascript:void(0)" style="cursor: default;">123n</a>
回答by Rocket Hazmat
回答by Rahul Tripathi
You need to remove the <a>tag to get rid of this.
您需要删除<a>标签才能摆脱这种情况。
or try using :-
或尝试使用:-
<a href="/" onclick="return false;">123n</a>
回答by venkatskpi
Tips 1: Using CSSpointer-events: none;
技巧 1:使用 CSSpointer-events: none;
Tips 2: Using JavaScriptjavascript:void(0)(This is a best practice)
技巧 2:使用 JavaScriptjavascript:void(0)(这是最佳实践)
<a href="javascript:void(0)"></a>
Tips 1: Using Jquery$('selector').attr("disabled","disabled");
技巧一:使用Jquery$('selector').attr("disabled","disabled");
回答by Syed
HTML:
HTML:
<a href="/" class="btn-disabled" disabled="disabled">123n</a>
CSS:
CSS:
.btn-disabled,
.btn-disabled[disabled] {
opacity: .4;
cursor: default !important;
pointer-events: none;
}
回答by Joel Adams
CSS only: this removes the link from the href.
仅 CSS:这会从href.
.disable {
pointer-events: none;
cursor: default;
}

