我有一个随机启用或禁用的类型文本输入..我想循环遍历所有未禁用的输入.. TIA!
答案 0 :(得分:3)
您可以使用enabled-selector和attribute equals selector查找已启用的元素,然后使用each()来迭代它们
$('input[type="text"]:enabled')
另一种方法是使用text-selector,
$('input:text:enabled')
这是首选方式,因为
$('<input>').is('[type=text]'); // false
$('<input>').is(':text'); // true
演示:Fiddle
答案 1 :(得分:0)
试试这个:
$("input:not(:disabled)").each(function(){
$(this).val("No Disable");
});
特定于启用的类型文本:
$("input[type=text]:enabled").each(function(){
$(this).val("No Disable");
});
答案 2 :(得分:0)
试试这个:
$( "input[type='text']:not([disabled])" ).each(function() {
// found one
// do something
});
这里重要的是jQuery :not()
选择器,在这种情况下,它选择所有不包含disabled属性的输入元素。