如何将下拉列表框的值复制到同一表中的所有列表框

时间:2019-04-10 16:09:47

标签: javascript php jquery

我遇到了一个问题,我想将填充的最后一个下拉列表框的值复制到定义的其余列表框。

这是我的代码:

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
    $("table input[name='copy']").click(function() {
      $(this).parents("tr").children("td:not(:last-child)").each(function(index, element) {
        if ($(element).children().length != 0) {
          $(element).nextAll(":not(:last-child)").html($(element).children().clone())
        }
      })
    });
  </script>
</head>
<body>
  <table>
    <tr>
      <th width="10%">id</th>
      <th width="10%">fn</th>
      <th width="10%">ln</th>
      <th width="10%">usr</th>
      <th width="10%">type</th>
      <th width="10%">1</th>
      <th width="10%">2</th>
      <th width="10%">3</th>
      <th width="10%">4</th>
      <th width="10%">5</th>
      <th width="10%">Copy</th>
    </tr>
    <tr>
      <td>1</td>
      <td>TE</td>
      <td>TE</td>
      <td>userTe</td>
      <td>fulltime</td>
      <td>
        <select class="t1">
          <option>CP</option>
          <option value="2">RC</option>
          <option value="3">CP</option>
        </select>
      </td>
      <td>
        <select class="t1">
          <option>CP</option>
          <option value="2">RC</option>
          <option value="3">CP</option>
        </select>
      </td>
      <td>
        <select class="t1">
          <option>CP</option>
          <option value="2">RC</option>
          <option value="3">CP</option>
        </select>
      </td>
      <td>
        <select class="t4">
          <option></option>
          <option value="2">RC</option>
          <option value="3">CP</option>
        </select>
      </td>
      <td>
        <select class="t5">
          <option></option>
          <option value="2">RC</option>
          <option value="3">CP</option>
        </select>
      </td>
      <td><input name="copy" type="submit"></td>
    </tr>
  </table>
</body>
</html>

我使用了以下小提琴,效果很好,但在我的计算机上不起作用... link to fiddle

有人可以告诉我该怎么做吗?预先感谢

预先感谢

0 个答案:

没有答案