我试图在原型框架上提交表单之前使用 jquery 验证,但在我仍然无法完成它的负载之后。我有以下代码。
<script>
jQuery(function (jQuery) {
jQuery('#edit_form').submit(function () {
var valid = true;
var errormsg = 'required!';
var errorcn = 'error';
jQuery('.' + errorcn, this).remove();
jQuery('.required-entry', this).each(function () {
var parent = jQuery(this).parent();
if (jQuery(this).val() == '') {
var msg = jQuery(this).attr('title');
msg = (msg != '') ? msg : errormsg;
jQuery('<span class="' + errorcn + '">' + msg + '</span>')
.appendTo(parent)
.fadeIn('fast')
.click(function () {
jQuery(this).remove();
})
valid = false;
};
});
return valid;
});
})
</script>
<table id="testform">
<tr>
<td style="text-align:left; padding-left:10px;font-family:segoeui"><input id="Desc2" name="Desc2" value="" class="required-entry input-text" type="text"title="Required" /></td>
<td class="mono" style="width:15%;"><input name="qta2" value="" class="qta required-entry input-text" type="text" title="Required" /></td>
<td style="width:15%;" class="mono"><input name="bpa2" value="" class="bpa required-entry input-text" type="text" title="Required" /></td>
</tr>
<tr>
<td style="text-align:left; padding-left:10px;font-family:segoeui"><input id="Desc3" name="Desc3" value="" class="required-entry input-text" type="text"title="Required" /></td>
<td class="mono" style="width:15%;"><input id="qta3" name="qta3" value="" class="qta required-entry input-text" type="text" title="Required" /></td>
<td style="width:15%;" class="mono"><input id="bpa3" name="bpa3" value="" class="bpa required-entry input-text" type="text" title="Required" /></td>
</tr>
<tr>
<td style="text-align:left; padding-left:10px;font-family:segoeui"><input id="Desc4" name="Desc4" value="" class="required-entry input-text" type="text"title="Required" /></td>
<td class="mono" style="width:15%;"><input id="qta4" name="qta4" value="" class="qta required-entry input-text" type="text" title="Required" /></td>
<td style="width:15%;" class="mono"><input id="bpa4" name="bpa4" value="" class="bpa required-entry input-text" type="text" title="Required" /></td>
</tr>
</table>
<div class="submit content-header">
<h3 class="icon-head head-products">Page Title</h3>
<p class="content-buttons form-buttons">
<button id="id_be" type="button" class="add" onclick="document.edit_form.submit();" style=""><span>Submit</span></button>
</p>
</div>
<form action="test.php?IID=1" method="post" id="edit_form" name="edit_form" enctype="multipart/form-data">
<input type="hidden" id="editform" name="editform" value="1" >
<div style="display:none"></div>
</form>
jsfiddle在这里http://jsfiddle.net/sammry/qBHLB/
表单只是在不验证必填字段的情况下得到处理。请帮忙!!!