【问题标题】:Select 2 fails to work, Cant pinpoint the reason选择2失败,无法查明原因
【发布时间】:2021-11-30 19:11:57
【问题描述】:

我有一个剃须刀页面, 使用以下内容:

@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 的打开下拉列表

【问题讨论】:

    标签: c# asp.net asp.net-core razor jquery-select2


    【解决方案1】:

    选择器$('multipleWriters') 错误

    要通过 id 选择必须是(注意前面的#

    $('#multipleWriters')
    

    如果您使用类名,则按类$('.classname') 选择(注意前面的点.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 2019-01-21
      • 2022-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多