简体   繁体   中英

How to install and work with jQuery Chosen plugin?

I downloaded jQuery's Chosen plugin, copied the chosen.min.css and chosen.jquery.min.js files in my project.

Copied link paths in my CSHTML:

<link href="~/Content/Bootstrap/css/chosen.min.css" rel="stylesheet" />
<script src="~/Content/Bootstrap/js/chosen.jquery.min.js" type="text/javascript"></script>

I have a dropdown list in my CSHTML, somewhat this way:

<div class="col-md-4">
     <div class="btn-group pull-left">
          <button type="button" class="btn dropdown-toggle btn-md set-border" data-toggle="dropdown" id="dropdownbtn">
              <span class="spn-action">Add new criteria</span><span class="caret" id="caretAdjustment"></span>
          </button>
          <ul class="dropdown-menu" id="chzn-select" role="menu">
              @foreach(var item in Model)
              {
                 <li onclick="ShowMessage('@item.Criteria')"><a href="#">@item.Criteria</a></li>
              }  
           </ul>
      </div>
</div>

My jQuery:

<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#chzn-select").as(Chosen).chosen();
        });
    });
</script>

But nothing as expected by 'Chosen' happens... Where am I going wrong?

Thanks in advance.

From the chosen you need a select element:

<select data-placeholder="Choose a country..." style="width:350px;" multiple class="chosen-select">

And after in js:

$(".chosen-select").chosen();

Check this fiddle too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM