我在提交错误的表单时使用'jquery validate'插件时试图获取错误容器的高度,但是当它出现时我似乎无法获得错误容器的高度值。警报框甚至没有显示。请问是什么解决方案?
以下是代码:
$(".validate").validate({
rules: {
j_username: "required"
},
submitHandler: function(form) {
//$(":submit", form).attr("disabled","disabled").val("Please wait....");
$(":submit", form).attr({
disabled: "disabled",
value: "Please wait...."
});
var errH = $("#errorMsgContainer").height();
if($("#errorMsgContainer").is(":visible")){
alert("visible and '#errorMsgContainer' height is: " + errH);
}
else{
alert("Not visible and '#errorMsgContainer' height is: " + errH);
}
form.submit();
return false;
},
messages: {
j_username: "Please type your email address correctly!",
j_password: "Your password and username do not match!"
},
ignore: ".catalogueDD",
errorLabelContainer: $("#errorMsgContainer")
});
感谢。
答案 0 :(得分:0)
如果元素没有占用文档中的任何空格,那么(':hidden')将返回true,即使它是有效可见的,相反,这可能更安全:
if( !$('#errorMsgContainer').is(':visible') ) {
// it's hidden, do something
}
else {
// it's not hidden so do something else
}
SOURCE :: http://www.electrictoolbox.com/jquery-element-is-visible/