所选的jQuery在选择时未关闭 [英] JQuery chosen not closing on select

查看:110
本文介绍了所选的jQuery在选择时未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQuery选择的控件.选择项目后,它仍保持打开状态,在单击它之前,它仍显示搜索文本框.我不希望这些事情发生.

I am using a JQuery chosen control. It remains open after item selection, also before clicking on it, it is displaying the search textbox. I don't want either of these things to be happening.

以下是使用EF在MVC中下拉菜单的代码:

Here's the code for the dropdown in MVC using EF:

<div class="form-group">
    @Html.LabelFor(model => model.Field, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownListFor(model => model.Field, null, htmlAttributes: new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.Field, "", new { @class = "text-danger" })
    </div>
</div>

这是脚本:

<script type="text/javascript">
    $("#Field").chosen();
</script>

我在这里想念什么.我以为这种行为默认存在?

what am I missing here. I thought this behaviour was there by default?

对于其他有此问题的人-我忘记了链接selected.css

To anyone else having this problem - I forgot to link the chosen.css

推荐答案

尝试一下;

<script type="text/javascript">

   $("#Field").chosen({
        max_selected_options: 1,
        allow_single_deselect: true, // check out what happens when you remove this option
        disable_search: true, // if you dont want to show search box
   }).removeAttr("multiple");

   $("#Field").on("chosen:maxselected",function(evt, params){
        $('#Field').trigger('chosen:close');
   });

</script>

这篇关于所选的jQuery在选择时未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆