sample_editable_1表格提交 前台校验单元格不能为空且为数字
点击提交是触发:
<table class="table table-striped table-hover table-bordered " id="sample_editable_1">
<thead>
<tr>
<th style="text-align:center" width="20%">商品名</th>
<th style="text-align:center" width="25%">商品备注</th>
<th style="text-align:center" width="20%">数量</th>
<th style="text-align:center" width="20%">单位</th>
<th style="text-align:center" width="15%">操作</th>
</tr>
</thead>
<tbody>
<#list purchaseApplyGoodsDetail as goods>
<tr class="">
<td class="center" style="text-align:center" width="20%">${goods.goodsName}</td>
<td class="center" style="text-align:center" width="25%">${goods.remarks}</td>
<td class="center" style="text-align:center" width="20%">${goods.quantity}</td>
<td class="center" style="text-align:center" width="20%">
<select>
<option value="" selected="true"></option>
<option <#if '${goods.quantifier}'=='1'> selected="true" </#if> value="1">个</option>
<option <#if '${goods.quantifier}'=='2'> selected="true" </#if> value="2">块</option>
<option <#if '${goods.quantifier}'=='3'> selected="true" </#if> value="3">台</option>
<option <#if '${goods.quantifier}'=='4'> selected="true" </#if> value="4">件</option>
<option <#if '${goods.quantifier}'=='5'> selected="true" </#if> value="5">本</option>
</select>
</td>
<td class="center" style="text-align:center" width="15%">
<a class="edit" href="javascript:;">Edit</a>
<a class="delete" href="javascript:;">Delete</a>
</td>
</tr>
</#list>
</tbody>
</table>
function check() {
var checkResult = true;$("#sample_editable_1 tr").each(function(){
var myTds = $(this).children("td").eq(0).find("input");
if (myTds.length > 0) {
if (myTds[0].value == "") {
alert("请输入商品名");
checkResult = false;
return checkResult;
}
if (myTds[0].value.length < 1 || myTds[0].value.length > 20) {
alert("商品名长度在1~20之间");
checkResult = false;
return checkResult;
}
}
myTds = $(this).children("td").eq(2).find("input");
if (myTds.length > 0) {
if (myTds[0].value == "") {
alert("请输入数量");
checkResult = false;
return checkResult;
}
if (!reg.test(myTds[0].value)) {
alert("数量必须是数字");
checkResult = false;
return checkResult;
}
}
});