使用js输入id(自动完成)并不起作用

时间:2018-03-25 13:06:58

标签: javascript php jquery

我的错误在哪里,在这个js中,因为它确实有效并且控制台我没有看到结果输入自动完成的任何内容,例如 如果您需要更多信息,请告诉我,我会补充。

谢谢

Html结果版本 注意:specification_row是一个增量,当你在表中添加一个新行时 外观$(document).ready(function()id="specificationName' + specification_row + '"是相同的,但确实无效。

表的

元素

<script type="text/javascript"><!--
  var specification_row = 3;

    $(document).ready(function() {
    $("#specificationName' + specification_row + '").tokenInput("http://....../products_specification_ajax.php" ,
        {
          tokenLimit: 1,
          resultsLimit: 5,
          onResult: function (results) {
            $.each(results, function (index, value) {
              value.name = value.id + " " + value.name;
            });
            return results;
          }
        });
  });


  function addSpecificationValue() {
   html  = '<tr id="specification-row' + specification_row + '">';

//specification_name
   html += '<td>';
   html += '  <input type="text" name="products_specification[' + specification_row + '][name]" value="" id="specificationName' + specification_row + '" class="form-control token-input" />';
   html += '  <input type="hidden" name="product_specification[' + specification_row + '][specification_id]" value="" />';
   html += '</td>';

//remove    
    html += '  <td class="text-md-right"><button type="button" onclick="$(\'#specification-row' + specification_row + '\').remove();" data-toggle="tooltip" title="Remove" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
    html += '</tr>';

    $('#specification tbody').append(html);

    specification_row++;
}

我的PHP代码

      $content .= '<tr id="specification-row' . $t . '">';
        $content .= '  <td>' . HTML::inputField('products_specification[' . $t . '][name]', $specification_name, 'class="form-control token-input" id="specificationName' . $t . '"', null, null, null);
</td>';
          $content .= ' </tr>';
          $content .= '    </tbody>
                              <tfoot>
                                <tr>
                                  <td colspan="5"></td>
                                  <td class="text-md-right"><button type="button" onclick="addSpecificationValue();" data-toggle="tooltip" title="' . $this->app->getDef('button_add') . '" class="btn btn-primary"><i class="fas fa-plus-circle"></i></button></td>                             
                                </tr>
                              </tfoot>
                            </table></td>
                          </tr>
                        </table>
                 ';



 $products_specification_ajax = OSCOM::link('products_specification_ajax.php');

          $output = <<<EOD
        <script type="text/javascript"><!--


          var specification_row = $t; // increment element 
// call token-input js for autocompletion : data list



            $(document).ready(function() {
            $("#specificationName' + specification_row + '").tokenInput("{$products_specification_ajax}" ,
                {
                  tokenLimit: 1,
                  resultsLimit: 5,
                  onResult: function (results) {
                    $.each(results, function (index, value) {
                      value.name = value.id + " " + value.name;
                    });
                    return results;
                  }
                });
          });

-- create new js row with all element

          function addSpecificationValue() {
           html  = '<tr id="specification-row' + specification_row + '">';

           html += '<td>';

-- input autocompketion call
           html += '  <input type="text" name="products_specification[' + specification_row + '][name]" value="" id="specificationName' + specification_row + '" class="form-control token-input" />';


           html += '  <input type="hidden" name="product_specification[' + specification_row + '][specification_id]" value="" />';
           html += '</td>';  
        //remove    
            html += '  <td class="text-md-right"><button type="button" onclick="$(\'#specification-row' + specification_row + '\').remove();" data-toggle="tooltip" title="Remove" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
            html += '</tr>';

            $('#specification tbody').append(html);

            specification_row++;
        }
        </script>
    EOD;

0 个答案:

没有答案