jQuery Chosen在填充时不显示数据占位符

我在我的ASP.NET MVC应用程序中使用jQuery Chosen插件.当dropdownlist中有项目时,data-placeholder属性不起作用.而不是显示认文本,它会自动选择列表中的第一个项目.

这是我如何定义我的下拉列表.

@Html.DropDownListFor(m => m.Keep,Model.Data,new { @class = "chzn-select",data_placeholder = "Default..." })

如果Model.Data为空(它使用EF填充在视图模型中),则会显示认文本.否则,选择第一个项目.我总是希望我的下拉列表显示认值.

我通过$(‘.chzn-select’)应用插件.selected();没什么特别的.

有任何想法吗 ?提前致谢.

解决方法

您需要先添加一个空选项.

根据文档 – http://harvesthq.github.com/chosen/

Note: on single selects,the first element is assumed to be selected by the browser. To take advantage of the default text support,you will need to include a blank option as the first element of your select list.

也许使用jQuery添加

$(".chzn-select").prepend("<option></option>");

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...