我遇到了一个jquery.validate的问题。我有2个表单在1页上。第一个表单是图像上传。ajax劫持了其中的帖子,上传图像并将图像返回到屏幕,然后使用图像名称更新第二个表单中的隐藏输入(VLogo)。
我想做的是,如果隐藏的输入是空的,当第二个表单被验证时,第一个表单中的元素被高亮显示。我希望这是有意义的。希望有人能帮我。下面是表单的一个示例:
表单1-图像上传表
<form class="logoform" id="mLogo">
<tr>
<td>
<div id="logoContainer">
<span id="logoarea"> <img id="thumb" width="100px" height="100px" src="images/logo_placeholder.gif" border="0"></span>
</div>
</td>
<td colspan=2>
<table cellspacing=0 cellpadding=3 border=0>
<tr>
<td class="field"><input type="file" name="upload1" id="upload1" class="required"></td>
</tr>
<tr>
<td align="right"><input type="submit" value="Add Logo" name="addlogo" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"></td>
</tr>
<tr>
<td class="flabel"><label for="volvoLogo">Logo Upload</label></td>
</tr>
</table>
</td>
</tr>
</form>表单2数据收集
<form id="customcal" action="processCal.cfm" method="post">
<tr>
<td colspan=3 class="flabel"><label for="c_dealerName">Dealer Name</label></td>
</tr>
<tr>
<td colspan=3 class="field"><input type="text" name="c_dealerName" class="required"></td>
</tr>
<tr>
<td class="flabel"><label for="c_phone">Phone</label></td>
<td colspan=2 class="flabel"><label for="c_fax">Fax</label></td>
</tr>
<tr>
<td class="field"><input type="text" name="c_phone" class="required phone"></td>
<td class="field" colspan=2><input type="text" name="c_fax" class="required phone"></td>
</tr>
<tr>
<td colspan=3 class="flabel"><label for="c_website">Website Address</label></td>
</tr>
<tr>
<td colspan=3 class="field"><input type="text" name="c_website" class="required"></td>
</tr>
<input type="hidden" name="vLogo" id="vLogo" class="required">
<tr>
<td colspan=3 align="right"><input type="submit" value="Submit" id="subform" name="submit" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"></td>
</tr>
</form>到目前为止的JQUERY验证
$("#customcal").validate({
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted below'
: 'You missed ' + errors + ' fields. They have been highlighted below';
$("div.error span").html(message);
$("div.error").show();
} else {
$("div.error").hide();
}
},
onkeyup: false,
submitHandler: function() {
$("div.error").hide();
form.submit();
}
});发布于 2011-08-05 04:38:28
首先,您需要为表单提供一个通用的类.form_validate或其他通用的类。
然后在表单上执行each循环,并将验证应用于该项。
$('.form_validate').each(function(i, form){
$(form).validate({
/* Your Validation Code */
});
});https://stackoverflow.com/questions/6947542
复制相似问题