【发布时间】:2014-10-11 07:24:41
【问题描述】:
我正在尝试启用我在此函数中调用的每个文本字段,但我不想启用 type="file" 字段。发生的情况是 type="file" 字段无论如何都被启用了。我错过了什么吗?
function disabled_fields(fields, state) {
if(state == true) {
$(fields).each(function() {
$(this).attr('disabled', true);
});
} else {
if(state == false) {
$(fields).each(function() {
if($(this).attr('type') != 'file') {
$(this).attr('disabled', false);
}
});
}
}
};
// Runs like this
disabled_fields('input, textarea', false);
【问题讨论】:
-
如果你尝试
.prop("disable", true)会发生什么?还有一点注意:你不必检查状态,你可以直接将状态设置为true或false。 -
添加一个小提琴,让它变得更好。
标签: jquery each disabled-input