1

我正在使用https://github.com/DubFriend/jquery.repeater转发器)来重复表单字段。

但是,该Add按钮不起作用,delete is working fine

$('.repeater').repeater();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
<table class="repeater">
  <tbody data-repeater-list>
    <tr data-repeater-item>
      <td>
        <select>
          <option value=" ">-- Select --</option>
          <option value="1">One</option>
          <option value="2">One</option>
          <option value="3">One</option>
          <option value="4">One</option>
          <option value="5">One</option>
        </select>
      </td>
      <td>
        <input data-repeater-delete type="button" value="Delete" />
      </td>
    </tr>
  </tbody>
  <input data-repeater-create type="button" value="Add" />

</table>

jsfiddle

4

2 回答 2

0

您需要用 tag 包装您的表格<form>并使用<form>tag class。在你的情况下:

$('.repeater').repeater();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>

<form class="repeater">
  <table class="repeater1">
    <tbody data-repeater-list>
      <tr data-repeater-item>
        <td>
          <select>
            <option value=" ">-- Select --</option>
            <option value="1">One</option>
            <option value="2">One</option>
            <option value="3">One</option>
            <option value="4">One</option>
            <option value="5">One</option>
          </select>
        </td>
        <td>
          <input data-repeater-delete type="button" value="Delete" />
        </td>
      </tr>
    </tbody>
    <input data-repeater-create type="button" value="Add" />

  </table>
</form>

于 2019-11-01T06:52:32.143 回答
0

请尝试将其包括Add在内data-repeater-list,如下所示,它将起作用。

$('.repeater').repeater();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
<table class="repeater">


  <tbody data-repeater-list>
    <tr>
      <td><input data-repeater-create type="button" value="Add"/></td>
    </tr>

    <tr data-repeater-item>
      <td>
        <select>
          <option value=" " >-- Select --</option>
          <option value="1" >One</option>
          <option value="2" >One</option>
          <option value="3" >One</option>
          <option value="4" >One</option>
          <option value="5" >One</option>
        </select>
      </td>
      <td>
        <input data-repeater-delete type="button" value="Delete"/>
      </td>
    </tr>
    
    
  </tbody>
  

</table>

于 2019-11-01T06:52:49.187 回答