Html 在 Bootstrap 中禁用链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29379979/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:45:34  来源:igfitidea点击:

Disable a link in Bootstrap

htmlcsstwitter-bootstraptwitter-bootstrap-3

提问by user2990084

The first example didn't work. I need to have always a list to disable links? Or what is wrong with my first demo?

第一个例子不起作用。我需要总是有一个列表来禁用链接?或者我的第一个演示有什么问题?

<a class="disabled" href="#">Disabled link</a>


<ul class="nav nav-pills">
  ...
  <li role="presentation" class="disabled"><a href="#">Disabled link</a></li>
  ...
</ul>

https://jsfiddle.net/7y0u2amy/

https://jsfiddle.net/7y0u2amy/

回答by Caampa

I think you need the btnclass.
It would be like this:

我认为你需要btn类。
它会是这样的:

<a class="btn disabled" href="#">Disabled link</a>

回答by Emanuela Colta

It seems that Bootstrap doesn't support disabled links. Instead of trying to add a Bootstrap class, you could add a class by your own and add some styling to it, just like this:

Bootstrap 似乎不支持禁用链接。您可以自己添加一个类并为其添加一些样式,而不是尝试添加 Bootstrap 类,就像这样:

a.disabled {
  /* Make the disabled links grayish*/
  color: gray;
  /* And disable the pointer events */
  pointer-events: none;
}
<!-- Make the disabled links unfocusable as well -->
<a href="#" class="disabled" tabindex="-1">Link to disable</a><br/>
<a href="#">Non-disabled Link</a>

回答by Cassandra

If what you're trying to do is disable an a link, there is no option to do this. I think you can find an answer that will work for you in this question here.

如果您尝试做的是禁用链接,则没有选项可以执行此操作。我认为您可以在此问题中找到适合您的答案。

One option here is to use

这里的一种选择是使用

<a href="/" onclick="return false;">123n</a>

Disabled href tag

禁用的 href 标签

回答by Mike

I just created my own version using CSS. As I need to disabled, then when document is ready use jQuery to make active. So that way a user cannot click on a button until after the document is ready. So i can substitute with AJAX instead. The way I came up with, was to add a class to the anchor tag itself and remove the class when document is ready. Could re-purpose this for your needs.

我刚刚使用 CSS 创建了自己的版本。因为我需要禁用,所以当文档准备好时使用 jQuery 激活。这样用户就不能在文档准备好之前点击按钮。所以我可以用 AJAX 代替。我想出的方法是向锚标记本身添加一个类,并在文档准备好时删除该类。可以根据您的需要重新调整它的用途。

CSS:

CSS:

a.disabled{
    pointer-events: none;
    cursor: default;
}

HTML:

HTML:

<a class="btn btn-info disabled">Link Text</a>

JS:

JS:

$(function(){
    $('a.disabled').on('click',function(event){
        event.preventDefault();
    }).removeClass('disabled');
});

回答by HelloWorld

You cant set links to "disabled" just system elements like input, textfield etc.

您不能将链接设置为“禁用”,只是系统元素,如输入、文本字段等。

But you can disable links with jQuery/JavaScript

但是您可以使用 jQuery/JavaScript 禁用链接

$('.disabled').click(function(e){
    e.preventDefault();
});

Just wrap the above code in whatever event you want to disable the links.

只需将上面的代码包装在您想要禁用链接的任何事件中。

回答by asifaftab87

I just removed 'href' attribute from that anchor tag which I want to disable

我刚刚从要禁用的锚标记中删除了“href”属性

$('#idOfAnchorTag').removeAttr('href');

$('#idOfAnchorTag').removeAttr('href');

$('#idOfAnchorTag').attr('class', $('#idOfAnchorTag').attr('class')+ ' disabled');

$('#idOfAnchorTag').attr('class', $('#idOfAnchorTag').attr('class')+'disabled');

To append my disabled value in class attribute

在类属性中附加我的禁用值

n it is completely disabled.

n 完全禁用。