gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:23:58 26 4
gpt4 key购买 nike

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

这就是我定义下拉列表的方式。

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

如果 Model.Data 为空(使用 EF 填充 View 模型),则显示默认文本。否则,将选择第一项。我总是希望我的下拉列表显示默认值。

我通过$('.chzn-select').chosen();应用该插件;没什么特别的。

有什么想法吗?提前致谢。

最佳答案

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

根据文档 - 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>");

关于jQuery Chosen 在填充时不显示数据占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11649375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com