like this page
我有下面的代码来显示一个下拉列表
<label>Data Source: </label><% = Html.DropDownList("DataSource", Model.CalendarDataSources, new { @id = "calendarDSDropdown", @class = "calendarDSDropdown" })%>
public IEnumerable<SelectListItem> CalendarDataSources;
我正在服务器上填充。我想给每个SelectListItem添加一个不同的backlog,但是我看不到如何做,因为SelectListItem只有一个backlog 名称、Id、选定项 属性
这可能吗
不幸的是内置的 DropDownList 助手不允许您设置 style 属性 option
DropDownList
style
option
或者,可以使用jQuery设置颜色:
$(function() { $('select#DataSource option').each(function() { var option = $(this); option.css( 'background-color', someFunctionThatMapsTheOptionValueToAColor(option.val()) ); }); });