根据第一个选择的选项显示第二个选择框? [英] Show a second select box based on the option chosen in the first?

查看:62
本文介绍了根据第一个选择的选项显示第二个选择框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下选择下拉框:

      <select name="selectcourier" required>
        <option value="">Please Select</option>
        <option value="collection">Collection</option>
        <option value="Interlink">Interlink</option>
        <option value="DespatchBay">Despatch Bay</option>
        <option value="International">International</option>
      </select> 

我想要做的是,如果选择了 Interlink,则其下方会出现一个辅助选择框,如果未选择它,则该框会消失,而选择了另一个选项.这是第二个选择下拉框.

What I want to do is if Interlink is selected a secondary select box appears below it and disappears if it unselected and another option is chosen instead. This is the second select drop down box.

     <label>Select Shipping Courier:</label>
     <select name="selectcourier" required>
        <option value="1">Please Select</option>
        <option value="2">Next Day</option>
        <option value="3">2-3 Day</option>
        <option value="3">Pre 12</option>
     </select> 

我怎样才能让它发挥作用?

How can I go about getting this working?

推荐答案

<script>
$(function(){
    $('#s1').hide();

});
function call()
{

        var check=$('#s2').val();
    if(check=="Interlink")
        {
        $('#s1').show();
        }

其他{$('#s1').hide();}

else { $('#s1').hide(); }

    }
</script>


<select name="selectcourier" required onchange="call();" id="s2" >
        <option value="">Please Select</option>
        <option value="collection">Collection</option>
        <option value="Interlink">Interlink</option>
        <option value="DespatchBay">Despatch Bay</option>
        <option value="International">International</option>
      </select> 
      <label>Select Shipping Courier:</label>
     <select name="selectcourier" required id="s1">
        <option value="1">Please Select</option>
        <option value="2">Next Day</option>
        <option value="3">2-3 Day</option>
        <option value="3">Pre 12</option>
     </select> 

你可以使用上面的代码来完成你的任务

You can use the above code to achieve your task

这篇关于根据第一个选择的选项显示第二个选择框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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