以下if语句.
emptyFields = false;
$(".ClassNanme").each(function() {
if(($.trim($(this).val()) == "") && ($(this).css('display') != 'none' ) {
emptyFields = true;
return false; // break out of the each-loop
}
});
Run Code Online (Sandbox Code Playgroud)
但是不起作用,我不知道如何使用jquery检查css属性显示是否设置为none.
当其中一个对象为空或其css属性显示未设置为none时,应选择此if语句.
检查值是否为空是有效的,我所坚持的是检查对象是否隐藏(或显示:无).
谢谢.
塞萨尔.
emptyFields = false;
$(".ClassName").each(function() {
if($.trim($(this).val()) === "" && $(this).is(":hidden")) {
emptyFields = true;
return false; // break out of the each-loop
}
});
Run Code Online (Sandbox Code Playgroud)
is(":hidden")在我看来,使用是比检查实际的CSS值语法更清晰,更容易阅读.试一试.
此外,与空字符串进行比较时,请使用===(类型相等).
编辑:Gah,将"可见"改为"隐藏" - 我的错误.