I have a html field.
<select name="select-states" disabled="disabled"><option value="">Choose State »</option></select>
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');
I wan开发者_StackOverflow中文版t 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?
thank you
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.
To set the disabled
attribute, provide the attribute name (first parameter) along with a value (second parameter):
$('select[name="select-states"]').attr('disabled', 'disabled');
精彩评论