我正在使用jquery.validate.js插件进行对话框验证。我的问题是,我只想提交第一个有问题的字段来获得一个类,并且字段错误在字段旁边的淡出 div 中显示为提示。(现在写插件在每个字段上添加标签)
我希望我足够清楚!
先感谢您!!!
(如果您需要更多,请询问)
编辑
它的代码
$("#wdw1003_useraddform").validate({
rules : {
wdw1003_username : {
required : true
},
wdw1003_password : {
required : true
},
wdw1003_fullname : {
required : true
},
wdw1003_email : {
required : true,
email : true
}
},
messages : {
wdw1003_username : {
required : "Field User Name is required"
},
wdw1003_password : {
required : "Password is required"
},
wdw1003_fullname : {
required : "Field Full Name is required"
},
wdw1003_email : {
required : "Field E-mail is required",
email : "Is not a valid e-mail"
}
}
});
在 ankur20us 评论后编辑
表格是用这行生成的
$form = new Form('useraddform', '#', $id."_");
$form -> setRequired('<img src="images/required.png" alt="Required" align="absmiddle" />', '<img src="images/required.png" alt="Required" align="absmiddle" />' . $trans -> translate('denotes required field'));
$form -> addElement('text', 'username', $trans -> translate('User Name'));
$form -> addElement('password', 'password', $trans -> translate('Password'));
$form -> addElement('text', 'fullname', $trans -> translate('Full Name'));
$form -> addElement('text', 'email', $trans -> translate('E-mail'));
$form -> addElement('select', 'perms', $trans -> translate('Permissions'), array('options' => $perms, 'value' => 'level1'));
$form -> addElement('select', 'status', $trans -> translate('Status'), array('options' => $status, 'size' => "1"));
$form -> addElement('textarea', 'comments', $trans -> translate('Comments'));
$form -> addElement('select', 'lang', $trans -> translate('Language'), array('options' => $langs, 'size' => "1"));
$form -> addElement('submit', 'submit', $trans -> translate('Create User'), array('style' => "clear:both; float:right; margin-right: 8%;"));
上面的 javascript 来自这些行
$form -> addRule('username', 'required', $trans -> translate('Field User Name is required'));
$form -> addRule('password', 'required', $trans -> translate('Password is required'));
$form -> addRule('fullname', 'required', $trans -> translate('Field Full Name is required'));
$form -> addRule('email', 'required', $trans -> translate('Field E-mail is required'));
$form -> addRule('email', 'email', $trans -> translate('Is not a valid e-mail'));
所以我不能改变太多!!!