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选择/下拉框示例
<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 :(得分:0)
只需使用removeAttr()方法即可。例如:
if($("#country option:selected").val()=="NONE"){
$('#state').removeAttr('disabled');
}else {
$('#state').attr('disabled', 'disabled');
}