twitter-bootstrap – Bootstrap – 顯示焦點上的所有型別頭項
當文字輸入(id =“問題”)獲取焦點時,我想顯示所有Typeahead專案.
我該怎麼做?
使用Javascript:
function SetTypeahead() { $("#Questions").typeahead({ minLength: 0, source: [ "Q1?", "Q2?", "Q3?", "@4?" ] }); }
獲取最新的bootstrap typeahead外掛v2.1.2
此更新將允許最小長度為零以啟用全部顯示
<input id="typeaheadField" name="typeaheadField" type="text" placeholder="Start Typing"> $("#typeaheadField").typeahead({ minLength: 0, items: 9999, source: ["Alabama","Alaska","Arizona","Arkansas","California","Colorado", "Oregon"] });
那麼你必須將onFocus事件附加到你的元素,因為它沒有被外掛定義:
$("#typeaheadField").on('focus', $("#typeaheadField").typeahead.bind($("#typeaheadField"), 'lookup'));
在本地覆蓋引導型別頭css類也是一個好主意,為結果設定最大高度和垂直滾動,以防結果過多.
.typeahead { max-height: 200px; overflow-y: auto; overflow-x: hidden; }
http://stackoverflow.com/questions/12827483/bootstrap-show-all-typeahead-items-on-focus