我有以下 jQuery 代码:
$("#signUpFormSubmitButton").click(function(){
$('#processing').show();
});
这很好用。单击表单上的提交按钮时,我会显示一个正在处理的旋转图形。
但是,如果表单上有错误(表单尚未提交),我不想显示正在处理的旋转图形。我也使用 jQuery 验证我的表单,如果有错误,我会在表单输入字段中添加一个“错误”CSS 类。
我想使用 css 错误类作为标志。
我试过:
if (!$("#myForm input").hasClass("error") ) {
$('#processing').show();
}
但是没有用。非常感谢任何帮助。
最佳答案
尝试使用 toggle()方法和一个简单的选择器
$("#signUpFormSubmitButton").click(function(){
$('#processing').toggle($("#myForm input.error").length > 0);
});
toggle(showOrHide)
showOrHideA Boolean indicating whether to show or hide the elements.
关于jquery 在提交按钮单击时显示处理图像,但如果表单中存在 css 错误类则隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5517162/