我需要一个非常基本的客户端表单验证:每当遇到无效字段时,都会显示一个标准的 windows 对话框,停止检查剩余的字段,并取消提交。
用 jQuery 完成上述操作的最简单方法是什么?
我需要一个非常基本的客户端表单验证:每当遇到无效字段时,都会显示一个标准的 windows 对话框,停止检查剩余的字段,并取消提交。
用 jQuery 完成上述操作的最简单方法是什么?
You may try tagging all fields you need to validate with a class of "RequiredField" and then use Jquery to validate them all at once. For the ones that fail you can add a class of highlight to turn them, say, red.
After that you can show a warning that says the highlighted fields are invaild.
function CheckStandardInputs(){
//Check for required fields.
var ReqFields = $(".RequiredField[value='']");
if(ReqFields.size() > 0){
if(HighlightBlanks){
ReqFields.addClass("Highlight");
}
//Remove highlight on change.
ReqFields.change(function () {$(this).removeClass("Highlight");});
return false;
}else{
return true;
}
}
What's wrong with the standard jQuery validation plugin?