Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery Selected中选择All后不允许选择选项_Jquery_Jquery Chosen - Fatal编程技术网

在jquery Selected中选择All后不允许选择选项

在jquery Selected中选择All后不允许选择选项,jquery,jquery-chosen,Jquery,Jquery Chosen,我使用了Jquery选择的插件。我在下拉列表中动态填充了数据 我允许选择多个选项。但我的问题是,如果用户选择所有选项,则不允许选择其他选项。如果用户删除所有选项,则允许 选择Jquery: 全部的 一个 两个 那很容易。。您所要做的就是取消选择所有内容,但每次用户选择某个内容时,都会使用all选项。。。代码如下: //first we cache the all option selector var theAllOption = $('#test option[value="-1"]');

我使用了Jquery选择的插件。我在下拉列表中动态填充了数据

我允许选择多个选项。但我的问题是,如果用户选择所有选项,则不允许选择其他选项。如果用户删除所有选项,则允许

选择Jquery:


全部的
一个
两个

那很容易。。您所要做的就是取消选择所有内容,但每次用户选择某个内容时,都会使用all选项。。。代码如下:

//first we cache the all option selector
var theAllOption = $('#test option[value="-1"]');
$("#test").on({
    change: function() {
        var element = $(this);
        //if the all option is selected we find all the selected options and deselect them
        if (theAllOption.is(":selected")) {
            element.find("option:selected").not(theAllOption).removeAttr("selected");
        }
    }
});​
可在此处找到一个工作示例:


所选插件的工作示例:

这不适用于所选的jquery。我需要选择jquery的工作plugin@Harry很抱歉我以为你想要一个替代选择。。。无论如何,这里有一个经过调整的版本,用于选择“您只需触发元素更新”@AspiringAqib,在我这方面工作正常。。。试试我在答案后面附加的新版本。。如果它不起作用。。让我知道您使用的浏览器和版本:)@KarimMagdyMansour我使用的是chrome最新版本。我在fiddle上看到了您选择的插件示例。我已根据您的示例更新了代码,并通知您有任何更新吗?我试过下面的答案代码,但它不工作。
//first we cache the all option selector
var theAllOption = $('#test option[value="-1"]');
$("#test").on({
    change: function() {
        var element = $(this);
        //if the all option is selected we find all the selected options and deselect them
        if (theAllOption.is(":selected")) {
            element.find("option:selected").not(theAllOption).removeAttr("selected");
        }
    }
});​