1
我正在使用一個很好的腳本,可以讓我從'顏色'下拉列表中進行選擇。當我選擇第一個選項時,我在其中放置了另一個「數字」下拉菜單。但現在的問題是:當我在這個'數字'下拉列表中選擇一些東西時,selectmenu消失。我希望它留下來,並提供自己的超鏈接。我的代碼:jquery show dropdown from dropdown
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Select Box</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$(this).find("option:selected").each(function(){
if($(this).attr("value")=="red"){
$(".box").not(".red").hide();
$(".red").show();
}
else if($(this).attr("value")=="green"){
$(".box").not(".green").hide();
$(".green").show();
}
else if($(this).attr("value")=="blue"){
$(".box").not(".blue").hide();
$(".blue").show();
}
else{
$(".box").hide();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select>
<option>Choose Color</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="red box" style="margin-top:10px;"><select>
<option>Choose number</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
</body>
</html>
感謝,工程巨大。 –
@JandeVries歡迎您! – brso05