2012-03-28 57 views
1
How to show the dropdown Country blank when the State dropdown option is selected and also viceversa(country dropdown is selected and the state dropdown is blank 

我们是否需要在选项中包含选项空白或者是否有任何语法, 我已通过禁用选项完成,当我选择国家/地区下拉菜单时,禁用状态下拉菜单。 jQuery的选择/下拉框示例如何选择otehr下拉选项中的某个选项时显示下拉空白?

<script type="text/javascript" src="js/jquery.js"></script> 

</head> 

<body> 

<h1>jQuery select/dropdown box example</h1> 

<script type="text/javascript"> 

    $(document).ready(function(){ 

    $("#country").change(function() { 


    // disable the dropdown: 

if($("#country option:selected").val()=="NONE"){ 
    $('#state').attr('enabled','true'); 
}else { 
    $('#state').attr('disabled','true'); 
} 


    }); 

    }); 
</script> 
</head><body> 

<select id="country"> 
<option value="NONE">-- Select --</option> 
<option value="China">China</option> 
<option value="United State">United State</option> 
<option value="Malaysia">Malaysia</option> 
</select> 
<select id ="state"> 
<option value ="AP">AP</option> 
<option value ="SP">SP</select> 
</body> 
</html> 

回答

0

只需使用removeAttr()方法。例如:

if($("#country option:selected").val()=="NONE"){ 
    $('#state').removeAttr('disabled'); 
}else { 
    $('#state').attr('disabled', 'disabled'); 
}