0

我正在使用 twitter bootstrap 字体。

 $(document).ready(function() {
        $("#searchfield").typeahead({
            minLength: 3,
            source: ["type1", "type2", "dtype3", "dtype4"]
        });
    });

input当我专注于标签(“#searchfield”)时,即使它是空的,我也想在下拉菜单(建议下拉菜单)中显示所有内容。这意味着我希望在我没有输入任何字母时显示所有来源。如果我输入任何字母,它需要显示相关数据(打字头的正常功能。)

或者

点击某个链接。下拉菜单需要提供所有给定的来源。例子:

<a href="#someId">Click here to populate typehead in #searchfield input tag </a>
<input type="text" id="searchfield">

单击链接时,输入字段需要使用所有给定的源(type1, type2, dtype3,dtype4)填充下拉列表

4

1 回答 1

0

我像这样在插件中更改了以下方法

, lookup: function (event) {
      var that = this
        , items
        , q

      this.query = this.$element.val()

    //console.log(this.query);
    //alert("this.query"+ this.query);

      if (!this.query) {
         return this.shown ? this.hide() : this
      }

      items = $.grep(this.source, function (item) {
       if this.query == "*"
          return item
       else
          return that.matcher(item)

      })

        //console.log("==items=="+items.length);
        //console.log(items);

      items = this.sorter(items)

       if (!items.length) {
        return this.shown ? this.hide() : this
      }

      return this.render(items.slice(0, this.options.items)).show()
    }

并将点击事件绑定到锚标签(<a id="someID" ......

jQuery('#someID').click(function(){
     var $input = $("#seachfield");
     //add something to ensure the menu will be shown
      $input.val('*');
      $input.typeahead('lookup');
      $input.val('');


});

希望这对其他人有帮助..

于 2013-01-27T07:59:32.160 回答