Select 2 失败,无法查明原因
Select 2 fails to work, Cant pinpoint the reason
我有一个剃刀页面,
具有以下内容:
@section renderHead{
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
}
下拉菜单:
<div id="multiplySelect" class="col-lg-9 col-md-9 col-sm-12">
@if (Enumerable.Count(ViewBag.WriterList) == 0)
{
@Html.DropDownList("multipleWriters", (IEnumerable<SelectListItem>)ViewBag.WriterList, new { @class = "form-control", multiple = "multiple", disabled = "disabled" })
<label id="error" class="form_label_comment">אין קטגוריות קיימות.</label>
}
else
{
@Html.DropDownList("multipleWriters", (IEnumerable<SelectListItem>)ViewBag.WriterList, new { @class = "form-control", data_val = "false", multiple = "multiple", style = "width:100%;" })
}
</div>
以及 Select2 执行(当然在脚本标签内):
$('multipleWriters').select2({
language: "he",
allowClear: true,
placeholder: {
"id": "",
"text": ''
},
});
有点迷茫,现在我看到一个打开的下拉菜单,看起来一点也不像 Select2
select或$('multipleWriters')
是错误的
to select by id 必须是(注意前面的#
)
$('#multipleWriters')
或 select 通过 class $('.classname')
如果您使用 class 名称(注意前面的点 .
)
我有一个剃刀页面, 具有以下内容:
@section renderHead{
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
}
下拉菜单:
<div id="multiplySelect" class="col-lg-9 col-md-9 col-sm-12">
@if (Enumerable.Count(ViewBag.WriterList) == 0)
{
@Html.DropDownList("multipleWriters", (IEnumerable<SelectListItem>)ViewBag.WriterList, new { @class = "form-control", multiple = "multiple", disabled = "disabled" })
<label id="error" class="form_label_comment">אין קטגוריות קיימות.</label>
}
else
{
@Html.DropDownList("multipleWriters", (IEnumerable<SelectListItem>)ViewBag.WriterList, new { @class = "form-control", data_val = "false", multiple = "multiple", style = "width:100%;" })
}
</div>
以及 Select2 执行(当然在脚本标签内):
$('multipleWriters').select2({
language: "he",
allowClear: true,
placeholder: {
"id": "",
"text": ''
},
});
有点迷茫,现在我看到一个打开的下拉菜单,看起来一点也不像 Select2
select或$('multipleWriters')
是错误的
to select by id 必须是(注意前面的#
)
$('#multipleWriters')
或 select 通过 class $('.classname')
如果您使用 class 名称(注意前面的点 .
)