2012-04-16 11 views
4

私はjqueryオートコンプリートコンボボックスを使用しています。オートコンプリートJqueryUIコンボボックス+すべてのテキストを選択

訪問http://jqueryui.com/demos/autocomplete/#combobox

問題は、このコンボボックスを作成して、ボックス内をクリックすると、内部のテキストが選択され、古いテキストを消去せずに次の検索を開始できるようにしたいと思います。私は$(ドキュメント).ready ...

 //clear each option if its selected 
     $('#<%=combobox.ClientID %> option').each(function() { 
      $(this).removeAttr('selected') 
     }); 

     //set the first option as selected 
     $('#<%=combobox.ClientID %> option:first').attr('selected', 'selected'); 

     //set the text of the input field to the text of the first option 
     $('#<%=combobox.ClientID %> ').parent().children('input.ui-autocomplete-input').val(' '); 

くぼみの仕事...あなたの助けを事前に

おかげでテストのために試してみました

ソリューション。

答えて

2

$.select()が必要です。あなたの特別なケースでは、オートコンプリートボックスを作成するときにこれを行います:

$('#autocompletebox').autocomplete({...blablabla... }).focus(function() { $(this).find('input').select(); $(this).select(); }); 
+0

ありがとう!出来た!! – ysr

関連する問題