伙计们,我在由 jQuery-validate 处理的表单中有一个表格,在表格中我有几列需要在单击时进行编辑(然后更新隐藏的输入)。由于某种原因,只要验证代码在页面上,那么只要编辑字段,页面就会提交(非 ajax 版本)。删除验证码让可编辑功能正常工作..
这是我的表格:
<form name="newCountForm" id="newCountForm" action="" method="post" class="inputForm" onsubmit="return false;">
<fieldset>
<legend></legend>
<div>
<table id="newCountsTable" border="1" cellpadding="1" cellspacing="1" class="contentBox tablesorter">
<thead>
<tr class="title1">
<td colspan="11">Counts</td>
</tr>
<tr class="title2">
<th>SKU</th>
<th>OZ</th>
<th>Description</th>
<th colspan="2">Front</th>
<th colspan="2">Back</th>
<th>Damages</th>
<th colspan="2">Total</th>
</tr>
<tr class="title2">
<th colspan="3"> </th>
<th>Cases</th>
<th>Units</th>
<th>Cases</th>
<th>Units</th>
<th>Units</th>
<th>Cases</th>
<th>Units</th>
</tr>
</thead>
<tbody>
<tr id="newCount_ML05_row" class="row1">
<th>ML05</th>
<th>6 oz</th>
<th>1% MILK GALLON</th>
<th><span id="editme_cases_front_ML05" class="editHolder_cases">0</span><input type="hidden" name="cases[front][ML05]" id="cases_front_ML05" class="cases" value="0" /></th>
<th><span id="editme_units_front_ML05" class="editHolder_units">0</span><input type="hidden" name="units[front][ML05]" id="units_front_ML05" class="units" value="0" /></th>
<th><input type="text" name="cases[back][ML05]" id="cases_back_ML05" class="cases" size="5" maxlength="4" value="0" /></th>
<th><input type="text" name="units[back][ML05]" id="units_back_ML05" class="units" size="5" maxlength="4" value="0" /></th>
<th><input type="text" name="units[damages][ML05]" id="units_damages_ML05" class="units" size="5" maxlength="4" value="0" /></th>
<th class="right"><span id="cases_total_ML05">0</span></th>
<th class="right"><span id="units_total_ML05">0</span></th>
</tr>
<tr id="newCount_ML05_row" class="row2">
<th>ML05</th>
<th>6 OZ</th>
<th>1% MILK GALLON</th>
<th><span id="editme_cases_front_ML05" class="editHolder_cases">0</span><input type="hidden" name="cases[front][ML05]" id="cases_front_ML05" class="cases" value="0" /></th>
<th><span id="editme_units_front_ML05" class="editHolder_units">0</span><input type="hidden" name="units[front][ML05]" id="units_front_ML05" class="units" value="0" /></th>
<th><input type="text" name="cases[back][ML05]" id="cases_back_ML05" class="cases" size="5" maxlength="4" value="0" /></th>
<th><input type="text" name="units[back][ML05]" id="units_back_ML05" class="units" size="5" maxlength="4" value="0" /></th>
<th><input type="text" name="units[damages][ML05]" id="units_damages_ML05" class="units" size="5" maxlength="4" value="0" /></th>
<th class="right"><span id="cases_total_ML05">0</span></th>
<th class="right"><span id="units_total_ML05">0</span></th>
</tr>
</tbody>
</table></div>
<div><label for="count_date">Count Date </label> <input type="text" name="count_date" id="count_date" size="20" value="04/09/2012" class="required" /></div>
<div class="center"><input type="submit" class="button" value="Enter the Counts" /></div>
</fieldset>
</form>
这是jQuery:
$('#countsTable').tablesorter({ headers: { 7: { sorter: false } } });
$('#newCountsTable').tablesorter();
$('#count_date').datepicker({
showButtonPanel: true
});
function sumValues() {
var sum = 0;
.each(function () { sum += parseFloat(this.value) });
return sum;
}
var v = jQuery("#newCountForm").validate({
errorElement: "div",
errorClass: "validation-advice",
submitHandler: function(form) {
$('#newCountResponse').html('<img src="themes/default/icons/indicator.gif" alt="spinner" />');
jQuery.get('ajax.php?action=createCount&reprinttable=1&showButtons=1', $('#newCountForm').serialize(), function(data) {
// Clear the default row
$('#countsTableDefaultRow').remove();
// Update the table with the new row
$('#countsTable > tbody:last').append(data);
$('#countsTableUpdateNotice').html('<div class="updateNotice">A new row has been added to this table, inline editing for this new row will be disabled until the next page refresh.</div>');
// Show a success message
$('#newCountResponse').html(returnSuccessMessage('count'));
});
}
});
$('*[id^=newCount_]').each(function () {
var $row = $(this),
sku = this.id.replace(/newCount_(.*?)_row/, '$1');
$.each(['cases', 'units'], function (i, type) {
$row.on('change', '.' + type, function () {
$('#' + type + '_total_' + sku).text( sumValues($row.find('.' + type)) );
});
});
$.each(['editHolder_cases', 'editHolder_units'], function (i, type) {
realType = type.replace(/editHolder_/, '');
$("#editme_" + realType + "_front_" + sku).editable(function(value, settings) {
$("#" + realType + "_front_" + sku).val( value );
$('#' + realType + '_total_' + sku).text( sumValues($row.find('.' + realType)) );
alert("#" + realType + "_front_" + sku + " - " + value);
return(value);
}, {
cancel : 'Cancel',
submit : 'OK',
tooltip : 'Click to edit...'
});
});
});
编辑和提交时,我在萤火虫“验证器未定义”中得到这个,任何想法是什么导致这些错误?