Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Javascript 使用jquery选择select-filter_Javascript_Jquery_Asp.net_Jquery Chosen - Fatal编程技术网

Javascript 使用jquery选择select-filter

Javascript 使用jquery选择select-filter,javascript,jquery,asp.net,jquery-chosen,Javascript,Jquery,Asp.net,Jquery Chosen,我正在asp.net中使用选定的下拉列表。有办法过滤optgroup吗 有一个单选按钮列表控件,其值为US和UK。我想根据用户的单选按钮选择筛选下拉列表。如果选择“US”,则下拉列表应仅显示US optgroup记录 这里是jsfiddle 这就是我到目前为止所尝试的,但没有运气 ('#rbDistDiv input').change(function () { // The one that fires the event is always the

我正在asp.net中使用选定的下拉列表。有办法过滤optgroup吗

有一个单选按钮列表控件,其值为US和UK。我想根据用户的单选按钮选择筛选下拉列表。如果选择“US”,则下拉列表应仅显示US optgroup记录

这里是jsfiddle

这就是我到目前为止所尝试的,但没有运气

('#rbDistDiv input').change(function () {
            // The one that fires the event is always the
            // checked one; you don't need to test for this
            var ddlDist = $('#VCSdistSelect_ddlDist'), 
            val = $(this).val(),
            region = $('option:selected', this).text();

            $('span > optgroup', ddlDist).unwrap();
            if (val !== '%') {
                $('optgroup:not([label="' + region + '"])', ddlDist).wrap('<span/>');
            }


        });

您应该能够执行类似的操作:

$.selected.selected{ 宽度:“600px”, 允许单次取消选择:true, 搜索包含:true }; 让UK_optgroup=$optgroup-UK.clone; 让我们_optgroup=$optgroup-US.clone; 让CA_optgroup=$optgroup-CA.clone; 函数过滤器SelectedRadio{ 开关选择无线电{ 案例美国:返回美国\ optgroup 案例UK:返回UK_optgroup 案例CA:返回CA_optgroup } } $'[type=radio]'。关于“更改”,函数{ //此处仅用于清除屏幕上显示的选定项目 //选择后。如果愿意,可以删除此项。 $selected-item.html; //从这里开始的一切都是需要的。 $select 儿童 .删除“optgroup”; $select .appendfilterSelectthis.value .已选择:已更新; }; $select.on'change',functionevent{ $selected-item.htmlSelected item:+event.target.value+; }; 我们 英国 加利福尼亚州

选择您的选项 阿德里安 艾伦 艾伦B 约翰 比利 克里斯 加布里埃 莫德 摩根
更改单选按钮时,只需通过标签隐藏/显示它们

$'[type=radio]'。关于“更改”,函数{ $‘选择’ .val//如果已进行选择,则重置值 .find'optgroup'//查找组 .藏起来//把它们都藏起来 .filter'[label='+this.value+']'//查找与收音机匹配的 .show//show it } 我们 英国 亚伦 约翰
你能为呈现的单选按钮粘贴HTML吗?我已经将其添加到我的问题中。你将下拉列表呈现为?不是吗?我使用ListItem在代码隐藏中绑定它,然后将其包装为$selectdist_ddldDist option[division='UKM'].wrapAll;你也能把它贴出来吗?你能发布尽可能多的呈现HTML吗?我已经简化了我的问题。请检查一下,不工作。这是一个最新的jsfiddle.net/7ngftsq2,你是什么意思?。。这和我的代码一点也不一样。。我想你是想回应另一个答案。看起来这真的很奇怪。。。我已经更新了我的答案,以显示您如何完成此任务。@user1263981这就是您要找的吗?不起作用。这里有一个最新的HTML无效,您不能在select中使用span。有趣的是,你正在使用其他插件,这可能会把它搞砸。