使用JQuery,我需要选择满足以下条件的所有输入元素:
更新:我需要按顺序迭代结果。
'未被禁用' (:disabled) '并且' '非只读状态',
更新:我需要按顺序迭代结果。
'未被禁用' (:disabled) '并且' '非只读状态',
冗长地说:
$('input:not(:disabled):not([readonly])').each(function() {
$(this).foo();
});
或者更好的方式:
$('input:enabled:not([readonly])').each(function() {
$(this).foo();
});
编辑:根据您下面的答案,有一种更好的方法可以实现您想要做的事情:
$('input').focus(function(e) {
if($(this).is(':disabled, [readonly]')) {
$(this).next().focus();
e.preventDefault();
}
});
我真的需要这些:
$('input:not(input:enabled:not([readonly]))').each(function() {
//skip focus to readonly input
$(this).focus(function(){
$(this).nextAll('input:enabled:not([readonly])')[0].focus();
});
});