2013-06-04 32 views

回答

1

佔位符選項應該是documentation中指定的字符串。也就是說,你的代碼應該是:

$("#first").select2({ 
    placeholder: "Choose an option…" 
}); 

對於搜索輸入進行舍入:通過CSS自己做。當前版本(v3.4.0)尚未具有此「功能」。

+0

我試過,但它不工作。它是[這裏](http://jsbin.com/ohujix/1/edit) – Godfather

+1

我不驚訝地發現一個未經測試的代碼工作不正常(或者它沒有很好的記錄)。如果你想要,試試我自己的[bselect](http://gustavohenke.github.io/bselect/)。它還沒有所有這些功能,但我正在路上。 – gustavohenke

+0

對我來說很漂亮! –

6

你有一個空的選項添加到您的選擇元素的開頭:

<select name="first" id="first"> 
    <option></option> 
    ... 
</select> 

然後,只需添加一個佔位符,就像這樣:

$(document).ready(function(){ 
    $("#first").select2({ 
     placeholder: "Your placeholder", 
     allowClear: false 
    }); 
});