在Twitter的引导最好的方式来禁用按钮 [英] Best way to disable button in Twitter's Bootstrap

查看:143
本文介绍了在Twitter的引导最好的方式来禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,当涉及到禁用<按钮> <输入> < A>在班元素: .btn .btn小学,使用JavaScript / jQuery的。

I am confused when it comes to disabling a <button>, <input> or an <a> element with classes: .btn or .btn-primary, with JavaScript/jQuery.

我使用了下面的代码片断做到这一点:

I have used a following snippet to do that:

$('button').addClass('btn-disabled');
$('button').attr('disabled', 'disabled');
$('button').prop('disabled', true);

所以,如果我只是提供了 $('按钮')addClass(BTN-禁用'); 来我的元素,它会显示为残疾人,视觉,但功能将保持不变,这将是点击nontheless,因此,它的原因,我添加了 ATTR 设置的元素。

So, if I just provide the $('button').addClass('btn-disabled'); to my element, it will appear as disabled, visually, but the functionality will remain the same and it will be clickable nontheless, so that it the reason why I added the attr and prop settings to the element.

有没有人expirenced同样的问题在那里?这是这样做的正确的方式 - 在使用Twitter的引导

Has anyone expirenced this same issue out there? Is this the right way of doing this - while using Twitter's Bootstrap?

推荐答案

您只需要在 $('按钮')丙(禁用,真正的); 部分,按钮将自动禁用类。

You just need the $('button').prop('disabled', true); part, the button will automatically take the disabled class.

这篇关于在Twitter的引导最好的方式来禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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