如何解决jQuery验证中不再需要动态字段
在这里,我要制作从ajax页面调用的所有必需的动态字段,因此为了编写所有必需的字段,我编写了这样的代码
<script src="http://demo.expertPHP.in/js/jquery.validate.min.js"></script>
<script>
$('#toUploadButton').on('click',function(e){
e.preventDefault();
e.stopPropagation();
$('input.product_price').each(function() {
$(this).rules("add",{
required:true,messages: {
required: "Name is required",}
});
});
e.preventDefault();
$("#add_product").validate();
});
</script>
我的ajax视图文件如下
<tr class="tr_clone_product ajax_result">
<td style="width:200px;"><input class="product_price" type="text" name="product_price[]" id="product_price" style="width:200px;"></td>
</tr>
<form method="POST" name="add_product" id="add_product" enctype="multipart/form-data" action="{{ url('/admin/products/store') }}">
@csrf
<div class="col-12">
<table class="table table-bordered all_products">
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Qty</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody class="product_list">
</tbody>
</table>
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="toUploadButton" type="button" id="toUploadButton" class="btn btn-primary">Submit</button>
</div>
</div>
在这里,类product_list
的位置正在加载ajax页面,我想使ajax页面内的所有字段都成为必需字段,但问题是仅第一行成为必需字段
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。