jQuery验证中不再需要动态字段

问题描述

enter image description here

在这里,我要制作从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 (将#修改为@)