简体   繁体   English

禁用Twitter Bootstrap按钮(链接)

[英]Making a Twitter Bootstrap button (link) disabled

What's the real and working way to make a twitter bootstrap button (which is a LINK ) disabled? 禁用Twitter Bootstrap按钮(这是LINK )的真正有效方法是什么? They mostly suggest that it is: 他们大多建议是:

$("#my_btn").prop("disabled", true); //1
//or
$("#my_btn").attr("disabled", true); //2

But this does NOT work. 但是,这并不工作。 What does work? 有什么用?

A link doesn't actually have a disabled attribute. 链接实际上没有disabled属性。

Instead, you'll need to add the .disabled css class. 相反,您需要添加.disabled css类。

$("#my_btn").addClass("disabled");

http://getbootstrap.com/css/#buttons-disabled (The section on Anchor element ) http://getbootstrap.com/css/#buttons-disabled (有关Anchor元素的部分)

As per the discussion below, you should note that this isn't a sure-fire way of actually disabling the link in all browsers. 根据下面的讨论,您应该注意,这并不是在所有浏览器中实际禁用链接的肯定方法。 It only uses CSS's pointer-events: none , which isn't as robust as the disabled attribute on a <button> element. 它仅使用CSS的pointer-events: none ,不如<button>元素上的disabled属性强大。

What version of jQuery you using? 您使用什么版本的jQuery? If you need disable a link, you can add a CSS class .disabled to that link with this jQuery command: 如果您需要禁用链接,则可以使用以下jQuery命令将CSS类.disabled添加到该链接:

$("#my_btn").addClass("disabled");

This code below is working for INPUT only 以下代码仅适用于INPUT

jQuery 1.6+ jQuery 1.6以上

$("input").prop('disabled', true);
$("input").prop('disabled', false);

jQuery 1.5 and below jQuery 1.5及以下

$("input").attr('disabled','disabled');
$("input").removeAttr('disabled');

In any version of jQuery 在任何版本的jQuery中

// assuming an event handler thus 'this'
this.disabled = true;

You can check this thread: Disable/enable an input with jQuery? 您可以检查此线程: 禁用/启用jQuery输入? and here you will find your answer I hope :) 我希望在这里您会找到答案:)

It's quite simple! 很简单!

just add the disabled class. 只需添加禁用的类。 Disabled: 禁用:

<button class="btn btn-default disabled">Text</button>

Non disabled: 非残疾人:

  <button class="btn btn-default">Text</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM