Javascript 所选Jquery未在选择时关闭

Javascript 所选Jquery未在选择时关闭,javascript,jquery-chosen,Javascript,Jquery Chosen,我有一个选择的模态。模态是用ajax加载的。 我希望上面的select使用SELECTED,因此在我的成功事件中,我有以下几点: $.ajax({ url: $params.testPlanImportPath, method: 'POST' }).success(function (response) { $modal.html(response).modal('show') $modal.find('#test_plan_form_project').chos

我有一个选择的模态。模态是用ajax加载的。 我希望上面的select使用SELECTED,因此在我的成功事件中,我有以下几点:

$.ajax({
    url: $params.testPlanImportPath,
    method: 'POST'
}).success(function (response) {
    $modal.html(response).modal('show')
    $modal.find('#test_plan_form_project').chosen({
        width: '100%'
    });
});
到目前为止,该部分运行良好,唯一的问题是我希望在单击某个项目时关闭选择。我相信这应该是默认行为,但出于某种原因,它对我不起作用。我在我的网站上选择了其他的,没有问题

我尝试添加一个事件以在选中它时手动关闭它,但它没有执行任何操作:

$modal.find('#test_plan_form_project').chosen({width:'100%'}).on('change', function(){
     //the code here was executed but it didn't close anyway
     console.log('close');
     $modal.find('#test_plan_form_project').trigger("chosen:close")
});
我还尝试添加我在其他chosens中的选项,但没有效果

$modal.find('#test_plan_form_project').chosen({
    width: '100%',
    allow_single_deselect: true,
    search_contains: true,
    disable_search_threshold: 10
});
控制台中任何一点都没有错误,事件中的my
console.log()
显示正确。如果我删除了select,select会像预期的那样工作,但是我真的希望有一个选中的界面

我觉得我可能错过了一些明显的东西

选择的html(带细枝)


Projet
{项目%中的项目为%}
{{project.name}
{%endfor%}
我知道有一个非常类似的问题:


我已经看了这个问题,但唯一的答案没有帮助,在这种情况下的问题是一个失踪的.css,这不是我的问题

您可以手动删除
选择的下拉菜单
,方法是删除
选择的活动容器
,以及打开下拉菜单时自动生成的
选择的下拉菜单
类:

var chosenContainer = $('.chosen-container');
chosenContainer.removeClass('chosen-container-active').removeClass('chosen-with-drop');

所选的是来自asp的元素?正确的?有任何引导涉及吗?请张贴一个。没有asp,我使用PHP与symfony框架,我使用引导是的。
var chosenContainer = $('.chosen-container');
chosenContainer.removeClass('chosen-container-active').removeClass('chosen-with-drop');