doubing3662 2014-09-29 11:42
浏览 271
已采纳

显示和隐藏选择选项

I've created a very basic form that has 2 dropdown lists.

Each list contains the same entries:

<option value='1234:0'>Closed</option>
<option value='4567:2'>Open</option>
<option value='6857:1'>Dead</option>
<option value='9856:1'>Alive</option>
<option value='0000:0'>Other</option>

If an entry in dropdown 1 is selected, then that entry should be removed from dropdown 2

If a different entry is selected in dropdown 1, then that should be removed from dropdown 2 and the original entry returned to dropdown 2

if nothing is selected in dropdown 1, then all options should be shown in dropdown 2.

I've created a FIDDLE, showing how far I've got... it's not very far.

Can any one help with this ?

Thanks

  • 写回答

2条回答 默认 最新

  • douyongdao4046 2014-09-29 11:53
    关注

    Try this

    $(function(){
    
        $('#test').change(function () {
    
            var selected = $(this).val();   
    
            $("#test2 option").show();
    
            $("#test2 option[value='" + selected + "']").hide();
    
        }); 
    
    }); 
    

    If you want to use text you can try this

    $(function(){
    
        $('#test').change(function () {
    
            var selected = $('option:selected', this).text();
    
            $("#test2 option").each(function(){
    
                if($(this).text() == selected) {
    
                    $(this).hide();
    
                } else {
    
                    $(this).show();
                }
    
            })
    
        }); 
    
    }); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码