【问题标题】:jquer autocomplete of textbox on html tablehtml表上文本框的jquery自动完成
【发布时间】:2017-08-13 05:18:48
【问题描述】:

如何在 html 表上做 jquery 自动完成

我有文本框

<input type="text" value="" id="txtInput"/>

下面我有html表格

 <table>
    <tr>
        <td>Name1</td>
        <td>1</td>
    </tr>
    <tr>
       <td>Name2</td>
       <td>2</td>
    </tr>
    <tr>
       <td>Name3</td>
       <td>3</td>
    </tr>
 </table>

我正在使用 jquery 自动完成,如何从 table first td 过滤,我尝试使用以下脚本,但无法正常工作。

 var arrLinks = $('#tblData td:first').map(function () {
    return $(this).text();
}).get();
$("#search_by_team").autocomplete({
    source: function (response) {
        $('#tblData').map(function () {
            return $(this).find('td:first').text();
        });
    },

});

【问题讨论】:

    标签: jquery html autocomplete


    【解决方案1】:

    '#tblData td:first' 将只选择一个 td 元素,它是第一个 td,在本例中为 Name1。 选择所有第一个 tds

    var arrLinks = $('#tblData tr').map(function () {
        return $(this).find('td:first').text();
    }).get();
    

    检查代码笔:https://codepen.io/meharaj/pen/KmZEaJ?editors=1011

    【讨论】:

      【解决方案2】:
      var arrLinks = $('#tblData td:first').map(function () {
      return $(this).text();}).get();
      $("#search_by_team").autocomplete({
      source: arrLinks });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-26
        • 2014-12-15
        • 1970-01-01
        相关资源
        最近更新 更多