0

我正在为我的问题再次寻求帮助。这只是我的条件下拉列表的延续。

<select name="dropdownmain" id="" title="">
    <option value="dropdownmain1">dropdownmain1</option>
    <option value="dropdownmain2">dropdownmain2</option>
    <option value="dropdownmain3">dropdownmain3</option>
    <option value="dropdownmain4">dropdownmain4</option>
</select>



//if selected dropdownmain1 this dropdown will display
<select name="dropdownmain1" id="" title="">
    <option value="dropdownmain1-submenu1">dropdownmain1-submenu1</option>
    <option value="dropdownmain1-submenu2">dropdownmain1-submenu2</option>
    <option value="dropdownmain1-submenu3">dropdownmain1-submenu3</option>
    <option value="dropdownmain1-submenu4">dropdownmain1-submenu4</option>
</select>

//if selected dropdownmain2 this dropdown will display
<select name="dropdownmain2" id="" title="">
    <option value="dropdownmain2-submenu1">dropdownmain2-submenu1</option>
    <option value="dropdownmain2-submenu2">dropdownmain2-submenu2</option>
    <option value="dropdownmain2-submenu3">dropdownmain2-submenu3</option>
    <option value="dropdownmain2-submenu4">dropdownmain2-submenu4</option>
</select>

//if selected dropdownmain3 this dropdown will display
<select name="dropdownmain3" id="" title="">
    <option value="dropdownmain3-submenu1">dropdownmain3-submenu1</option>
    <option value="dropdownmain3-submenu2">dropdownmain3-submenu2</option>
    <option value="dropdownmain3-submenu3">dropdownmain3-submenu3</option>
    <option value="dropdownmain3-submenu4">dropdownmain3-submenu4</option>
</select>

//if selected dropdownmain4 this dropdown will display
<select name="dropdownmain4" id="" title="">
    <option value="dropdownmain4-submenu1">dropdownmain4-submenu1</option>
    <option value="dropdownmain4-submenu2">dropdownmain4-submenu2</option>
    <option value="dropdownmain4-submenu3">dropdownmain4-submenu3</option>
    <option value="dropdownmain4-submenu4">dropdownmain4-submenu4</option>
</select>

**im using this js code**

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$('select[name!="dropdownmain"]').hide();
$('select[name="' + $('select[name="dropdownmain"]').val() + '"]').show();
$('select[name="dropdownmain"]').change(function(){
    $('select[name!="dropdownmain"]').hide();
    $('select[name="' + $(this).val() + '"]').show();
});
});//]]>  

</script>

单击按钮时如何获取所选下拉列表的值?

4

5 回答 5

1

给子菜单一个通用的类名!,并给主选择一个ID!

jQuery 代码可以简化为:

$('#dropdownmain').change(function() {
    $('.submenu').hide();
    $('.submenu[name="' + $(this).val() + '"]').show();
});

http://jsfiddle.net/samliew/jKUBb/

然后获取所选子菜单项的值:

$('.submenu').change(function() {
    alert($(this).val());
});
于 2013-04-24T07:12:29.437 回答
0

可能是这样的(如果我明白你想要什么):

$("#button").click(function() {
    var selected = $('select[name="dropdownmain"]').val();
    alert($('select[name="' + selected + '"]').val());
});
于 2013-04-24T07:07:30.980 回答
0

$('select[name="' + $('select[name="dropdownmain"]').val() + '"]').val()

于 2013-04-24T07:07:35.870 回答
0

利用:

var e = document.getElementsByName("dropdownmain")[0];
var strUser = e.options[e.selectedIndex].value;
于 2013-04-24T07:08:50.867 回答
0

如果要从当前显示的选择中获取所有值:

 $("select:visible").each(function() {
    console.log( $(this).attr('name') + " have value : " +   $(this).val() );               
  });

这是一个工作示例:http: //jsfiddle.net/GAe7D/1/

于 2013-04-24T07:09:55.853 回答