4

我永远无法在 Select2 JQuery 插件中定义占位符文本。我试过代码

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

但这对我不起作用。我的代码在这里

还有,如何将搜索的矩形变成四舍五入,Select2 的版本是什么?

4

2 回答 2

7

您必须在选择元素的开头添加一个空选项:

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

然后像这样简单地添加一个占位符:

$(document).ready(function(){
    $("#first").select2({
        placeholder: "Your placeholder",
        allowClear: false
    });
});
于 2015-07-14T07:26:03.423 回答
2

The placeholder option should be a string as specified in the documentation. That being said, your code should be just:

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

For the search input to be rounded: do it yourself via CSS. Current version (v3.4.0) doesn't have this "feature" yet.

于 2013-06-04T15:34:30.500 回答