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

问题描述

在禁用 元素时,我很困惑类:.btn.btn-primary,使用 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);

所以,如果我只提供 $('button').addClass('btn-disabled'); 到我的元素,它会在视觉上显示为禁用,但功能将保持相同,并且仍然可以点击,这就是我向元素添加 attrprop 设置的原因.

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.

有没有人解决过同样的问题?在使用 Twitter 的 Bootstrap 时,这样做是否正确?

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

推荐答案

你只需要 $('button').prop('disabled', true); 部分,按钮会自动参加残疾人班.

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

这篇关于在 Twitter 的 Bootstrap 中禁用按钮的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!