我正在为我的问题再次寻求帮助。这只是我的条件下拉列表的延续。
<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>
单击按钮时,如何获取所选下拉列表的值?
答案 0 :(得分:0)
这样的事情(如果我明白你想要的话):
$("#button").click(function() {
var selected = $('select[name="dropdownmain"]').val();
alert($('select[name="' + selected + '"]').val());
});
答案 1 :(得分:0)
$('select[name="' + $('select[name="dropdownmain"]').val() + '"]').val()
答案 2 :(得分:0)
使用:
var e = document.getElementsByName("dropdownmain")[0];
var strUser = e.options[e.selectedIndex].value;
答案 3 :(得分:0)
如果您想从当前显示的所有值中选择:
$("select:visible").each(function() {
console.log( $(this).attr('name') + " have value : " + $(this).val() );
});
以下是一个工作示例:http://jsfiddle.net/GAe7D/1/
答案 4 :(得分:0)
为子菜单指定一个公共类名称,也为主要选择一个ID!
jQuery代码可以简化为:
$('#dropdownmain').change(function() {
$('.submenu').hide();
$('.submenu[name="' + $(this).val() + '"]').show();
});
http://jsfiddle.net/samliew/jKUBb/
然后获取所选子菜单项的值:
$('.submenu').change(function() {
alert($(this).val());
});