如何确保两个选择菜单值与jquery不同? [英] How to make sure two select menu values are not the same with jquery?

查看:88
本文介绍了如何确保两个选择菜单值与jquery不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的选择菜单(菜单A和菜单B).两者具有相同的值.如何确保提交时所选菜单A的值不等于菜单B的值?如果选择的菜单A在菜单B上变为不可选择,那会很酷吗?

I have two different select menus (menu A and menu B). Both with the same values. How do I make sure selected menu A value is not equal to menu B value onsubmit? Would be cool if the selected menu A becomes non selectable on menu B?

有什么建议吗?

推荐答案

使用以下代码禁用第二个选择中的选项

Use the following code to diable the option in the second select

$('.select1').on('change',function(){
 var optionInSelect2 = $('.select2').find('option[value="'+$(this).val()+'"]');
 if(optionInSelect2.length) {
   optionInSelect2.attr('disabled','disabled');
  }
});

演示

这篇关于如何确保两个选择菜单值与jquery不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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