Javascript jquery 自动完成输入无效

Javascript jquery AutoComplate İnput not Working

Javascript jquery AutoComplate İnput 不工作。我可以试试,但不是这个。添加包 link 但 AutoComplate 输入不起作用。 我只想在自动完成输入工作后添加包。只有这个..我认为 insertCell Hard this.I 不理解这个。 id ='dap'

$(function() {
  var availableTags = [
    "arta",
    "barta",
    "barta2",
  ];


  $("#dap").autocomplete({
    source: availableTags
  });
});
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <title></title>
</head>

<body>
  <form method="post" action="add.php">
    <table id="table1">
      <tr>
        <br>
        <td colspan="4"><a onclick="myFunction1()" style=" color: #000; margin-top: 10px"><i></i> Paket Ekle</a>&nbsp;&nbsp; <a onclick="myDeleteFunction1()" style="color: #000; margin-top: 10px"><i ></i> Paket Sil</a></td>

      </tr>
      <tr>

        <td valign="bottom"><strong>GTIP No.</strong></td>

      </tr>
      <tr>

        <td><input name="dap" type="text" style="width:90%; margin-top: 15px"></td>
        <script>
          var i = 1;

          function myFunction1() {
            var table = document.getElementById("table1");
            var row = table.insertRow(-1);
            var cell1 = row.insertCell(0);


            cell1.innerHTML = "<input name='dap" + i + "'  id='dap'  type='text'  style='width:90%;margin-top:15px;' >";

            i++;
          }

          function myDeleteFunction1() {
            document.getElementById("table1").deleteRow(-1);
          }
        </script>
    </table>
  </form>
</body>

</html>

您可以使用on在动态添加的元素上绑定事件

$(function() {
  var availableTags = [
    "arta",
    "barta",
    "barta2",
  ];


  $(document).on('keydown.autocomplete', '#dap', function() {
    $(this).autocomplete({
      source: availableTags
    });
  });
});
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <title></title>
</head>

<body>
  <form method="post" action="add.php">
    <table id="table1">
      <tr>
        <br>
        <td colspan="4"><a onclick="myFunction1()" style=" color: #000; margin-top: 10px"><i></i> Paket Ekle</a>&nbsp;&nbsp; <a onclick="myDeleteFunction1()" style="color: #000; margin-top: 10px"><i ></i> Paket Sil</a></td>

      </tr>
      <tr>

        <td valign="bottom"><strong>GTIP No.</strong></td>

      </tr>
      <tr>

        <td><input name="dap" type="text" style="width:90%; margin-top: 15px"></td>
        <script>
          var i = 1;

          function myFunction1() {
            var table = document.getElementById("table1");
            var row = table.insertRow(-1);
            var cell1 = row.insertCell(0);


            cell1.innerHTML = "<input name='dap" + i + "'  id='dap'  type='text'  style='width:90%;margin-top:15px;' >";

            i++;
          }

          function myDeleteFunction1() {
            document.getElementById("table1").deleteRow(-1);
          }
        </script>
    </table>
  </form>
</body>

</html>