根据另一个下拉列表中的所选项目更改下拉所选项目 [英] Change drop down selected item based on selected item of another drop down list

查看:88
本文介绍了根据另一个下拉列表中的所选项目更改下拉所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP.NET MVC 3上有两个下拉列表.当其中一个下拉列表设置为"Sole Proprietor"时,另一个需要设置为相同.

I have two drop down lists on my ASP.NET MVC 3. When one of the drop down lists is set to "Sole Proprietor", the other needs to be set to the same.

我确信JavaScript或jQuery对于这种事情非常简单,但是由于要手动而不是通过控制器填充下拉列表,因此我很难在网上找到一个很好的示例.

I'm sure the JavaScript, or jQuery, is very simple for something like this, however I am having a hard time finding a good example on the web since I am populating the drop down lists manually instead of through the controller.

有人可以帮助我提供代码,还是可以为我提供良好的资源?

Can someone either help me out with the code or point me to a good resource?

<select id="ProducerType" name="nmf" style="float:left;">
    <option value="Principal">Principal</option>
    <option value="Producer">Producer</option>
    <option value="SoleProprietor">Sole Proprietor</option>                
</select>

<select id="Role" name="nmf" style="float:left;">
    <option value="Agent">Agent</option>
    <option value="Financial Advisor">Financial Advisor</option>
    <option value="Platform">Platform</option>
    <option value="Principla_Owner">Principal/Owner</option>
    <option value="Registered Rep">Registered Rep</option>
    <option value="Sole Proprietor">Sole Proprietor</option>              
</select>

推荐答案

jsFiddle示例: http://jsfiddle.net/9GZQ2/

jsFiddle example : http://jsfiddle.net/9GZQ2/

我将两个下拉值都设置为"Sole Proprietor",您的代码的ProducerType选择中缺少空格

I set both dropdown values to "Sole Proprietor" your code has the space missing in the ProducerType select

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script type="text/javascript">
    $(function(){
        $("#ProducerType").change(function(){
           var value=$(this).val();
           if(value=="Sole Proprietor") $("#Role").val(value);
        });
        $("#Role").change(function(){
           var value=$(this).val();
           if(value=="Sole Proprietor") $("#ProducerType").val(value);
        });
    });
</script>

这篇关于根据另一个下拉列表中的所选项目更改下拉所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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