我如何在< select>中添加disabled = disabled属性使用jQuery吗? [英] How do i add disabled=disabled attribute to <select> using jQuery?
问题描述
我有一个html字段.
I have a html field.
<select name="select-states" disabled="disabled"><option value="">Choose State »</option></select>
该字段最初是禁用的,我想根据事件启用或禁用它.要启用它,我正在使用以下效果很好的jQuery.
initially the field is disabled, i want to enable or disable it based on events. to enable it i am using the following jQuery which works fine.
$('select[name="select-states"]').removeAttr('disabled');
我想使用jQuery重新启用它,对此我尝试使用它不起作用.
I want to re-enable it using jQuery, for which i tried using this which does not work.
$('select[name="select-states"]').attr('disabled');
我想念什么?正确的语法是什么?
What am i missing? which is the correct syntax for this?
谢谢
推荐答案
在您的代码中,您仅向 .attr()
.这表明该函数应只返回该元素的disabled
属性的值.
In your code, you provide only one parameter to .attr()
. This indicates that the function should just return the value for the disabled
attribute of that element.
要设置disabled
属性,提供属性名称(第一个参数)以及值(第二个参数):
$('select[name="select-states"]').attr('disabled', 'disabled');
这篇关于我如何在< select>中添加disabled = disabled属性使用jQuery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!