我有以下html代码:
<form>
<table>
<tbody>
<tr>
<td>
<span>Quantity<span class="pull-right">3</span>
<input type="hidden" class="" value="3" name="quantity[]">
</td>
<td class="form-inline">
<label>Cantidad Warehouse</label>
<input id="qty_warehouse_1" type="text" name="cantidad_despacho[]" class="required input-mini">
</td>
</tr>
<tr>
<tr>
<td>
<span>Quantity<span class="pull-right">5</span>
<input type="hidden" class="" value="5" name="quantity[]">
</td>
<td class="form-inline">
<label>Cantidad Warehouse</label>
<input id="qty_warehouse_2" type="text" name="cantidad_despacho[]" class="required input-mini">
</td>
</tr>
<tr>
</tbody>
</table>
<button id="submit" value="send" name="button">Send</button>
</form>
每行都是动态生成的。我需要对名称为 Qty_warehouse 的每个输入执行验证,因此它的最大值不会大于同一行的隐藏值。这就是我一直在尝试做的事情:
$(document).ready(function() {
$("form").validate();
$("[id*='qty_warehouse']").rules("add", {
required: true,
max: function() {
return $(this).parents("tr").eq(0).find("input[name='quantity[]']").val();
},
min: 0,
messages: {
required: "Introduzca la cantidad disponible en despacho"
}
});
$("#submit").click(function() {
alert($("form").valid());
});
});
任何帮助将不胜感激。如果您想进行一些测试,这是小提琴链接。小提琴