2010-12-13 23 views

答えて

2

最も簡単な方法は、独自の_renderMenu関数を使用してjQuery UIオートコンプリートを拡張することです。

http://jqueryui.com/demos/autocomplete/#default

HTML:

<div class="ui-widget"> 
    <label for="tags">Tags: </label> 
    <input id="tags"> 
</div> 

のjQuery:

$(function() { //DOM Ready 
    var availableTags = [ 
     "ActionScript", 
     "AppleScript", 
     "Asp", 
     "BASIC", 
     "C", 
     "C++", 
     "Clojure", 
     "COBOL", 
     "ColdFusion", 
     "Erlang", 
     "Fortran", 
     "Groovy", 
     "Haskell", 
     "Java", 
     "JavaScript", 
     "Lisp", 
     "Perl", 
     "PHP", 
     "Python", 
     "Ruby", 
     "Scala", 
     "Scheme"]; 

    $.widget("custom.customcomplete", $.ui.autocomplete, { 
     // our fancy new _renderMenu function adds the header and footers! 
     _renderMenu: function(ul, items) { 
      var self = this; 
      $.each(items, function(index, item) { 
       if (index == 0) 
        ul.append('<li><input type="checkbox"> I\'m at the top! Choose me!</li>'); 
       self._renderItem(ul, item); 
       if(index == items.length - 1) 
        ul.append('<li><input type="checkbox"> I\'m at the bottom! Choose me!</li>'); 
      }); 
     } 
    }); 

    // note the new 'widget', extended from autocomplete above 
    $("#tags").customcomplete({ 
     source: availableTags 
    }); 

}); 

ここで働くの例を参照してください:http://jsfiddle.net/kJUdt/

+0

グレート答えが、本当に私をたくさん助けた私が提案し、多くの感謝 – LenPopLilly

+0

追加/前置演算子を使用する"if"と "lengthをチェックする"の代わりに: '_renderMenu:function(ul、items){ var that = this; ul.prepend( '

  • <入力の種類= "チェックボックス">私は一番上にあります!私を選んでください!
  • '); $ .each(items、function(index、item){ that._renderItemData(ul、item); }); ul.append( '
  • <入力の種類= "チェックボックス">私は下にあります!私を選んでください。
  • '); }、 ' –

    関連する問題