我在我的 asp.net mvc 5 应用程序中使用 Select2 插件。根据documentation
The placeholder option allows you to pass in a data object instead of just a string if you need more flexibility. The id of the data object should match the value of the placeholder option.
我已经完全做到了,但是占位符仍然没有出现。
代码:
model.Step6.Titles.Insert(0, new SelectListItem() { Text = "Select a Title", Value = "0", Selected = true });
@Html.DropDownListFor(model => model.Step6.Title, Model.Step6.Titles, new { id="teamtitle", @style = "width: 100%;"})
$("select").select2({
allowClear: true,
placeholder: {
id: "0",
placeholder: "Select an Title"
}
})
谁能告诉我我做错了什么?
最佳答案
我认为占位符是一个字符串。不是对象 https://select2.github.io/examples.html#placeholders
$("select").select2({
allowClear: true,
placeholder:"Select an Title"
})
关于javascript - Select2 -- 占位符不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37631319/