Html 在 Bootstrap 中禁用控件

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

Disabling Controls in Bootstrap

htmltwitter-bootstrap

提问by Firnas

I'm using Bootstrap css and js in my application. Accidentally I clicked on a disabled Dropdown list and found that it's opening the dropdown. I have made it readonlyin the attribute of the selectelement:

我在我的应用程序中使用 Bootstrap css 和 js。我不小心点击了一个禁用的下拉列表,发现它正在打开下拉列表。我已经readonlyselect元素的属性中做到了:

<select id="xxx" name="xxx" class="input-medium" readonly>

I have also tried setting readonly="true", but still the same.

我也试过设置readonly="true",但还是一样。

However, textbox control works fine, if you don't use jQuery.datepicker.

但是,如果您不使用 jQuery.datepicker,则文本框控件可以正常工作。

Is there a special way of making a dropdown control readonly when we use bootstrap?

当我们使用引导程序时,是否有一种特殊的方法可以使下拉控件只读?

回答by Jeromy French

No, Bootstrap does not introduce special considerations for disabling a drop-down.

不,Bootstrap 不会引入禁用下拉列表的特殊注意事项。

<select id="xxx" name="xxx" class="input-medium" disabled>

or

或者

<select id="xxx" name="xxx" class="input-medium" disabled="disabled">

will work. I prefer to give attributes values (as in the second form; in XHTML, attributes must have a value), but the HTML spec says:

将工作。我更喜欢给属性值(如在第二种形式中;在 XHTML 中,属性必须有一个值),但 HTML 规范说:

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

元素上布尔属性的存在表示真值,不存在该属性表示假值。

(from http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attribute)

(来自http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attribute

The key differences between read-only and disabled:*

只读和禁用之间的主要区别:*

The Disabled attribute

禁用属性

  • Values for disabled form elements are not passed to the processor method. The W3C calls this a successful element.(This works similar to form check boxes that are not checked.)
  • Some browsers may override or provide default styling for disabled form elements. (Gray out or emboss text) Internet Explorer 5.5 is particularly nasty about this.
  • Disabled form elements do not receive focus.
  • Disabled form elements are skipped in tabbing navigation.
  • 禁用表单元素的值不会传递给处理器方法。W3C 称这是一个成功的元素。(这类似于未选中的表单复选框。)
  • 某些浏览器可能会为禁用的表单元素覆盖或提供默认样式。(灰色或浮雕文本)Internet Explorer 5.5 对此尤其讨厌。
  • 禁用的表单元素不会获得焦点。
  • 在选项卡导航中跳过禁用的表单元素。

The Read Only Attribute

只读属性

  • Not all form elements have a readonly attribute. Most notable, the <SELECT>, <OPTION>, and <BUTTON>elements do not have readonly attributes (although thy both have disabled attributes)
  • Browsers provide no default overridden visual feedback that the form element is read only
  • Form elements with the readonly attribute set will get passed to the form processor.
  • Read only form elements can receive the focus
  • Read only form elements are included in tabbed navigation.
  • 并非所有表单元素都具有 readonly 属性。最值得注意的是<SELECT><OPTION>、 和<BUTTON>元素没有 readonly 属性(尽管你都具有 disabled 属性)
  • 浏览器不提供表单元素只读的默认覆盖视觉反馈
  • 设置了 readonly 属性的表单元素将被传递给表单处理器。
  • 只读表单元素可以接收焦点
  • 只读表单元素包含在选项卡式导航中。

*-blatant plagiarism from http://kreotekdev.wordpress.com/2007/11/08/disabled-vs-readonly-form-fields/

*-来自http://kreotekdev.wordpress.com/2007/11/08/disabled-vs-readonly-form-fields/ 的公然抄袭

回答by silly

try

尝试

$('#xxx').attr('disabled', true);

回答by Murat ?orlu

Try

尝试

<select id="xxx" name="xxx" class="input-medium" disabled>

回答by BigJoeNH

Remember for jQuery 1.6+ you should use the .prop()function.

请记住,对于 jQuery 1.6+,您应该使用该.prop()函数。

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

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

回答by Alagesan

<select id="message_tag">
<optgroup>
<option>
....
....
</option>
</optgroup>

here i just removed bootstrap css for only "select" element. using following css code.

在这里,我只是为“选择”元素删除了 bootstrap css。使用以下css代码。

#message_tag_chzn{
display: none;
}

 #message_tag{
  display: inline !important;
}

回答by zahid ullah

also you can use "readonly"

你也可以使用“只读”

<select id="xxx" name="xxx" class="input-medium" readonly>