我有一个下拉列表和5 div与它一起。我需要一次显示一个特定的div和隐藏其他。这是我的方法 这是我的代码如何有效地隐藏其他同胞使用jquery
<div data-role="content">
<div id="tab-1">
<br />
<div id="one" style="width: device-width; height: 150px;"></div>
<div id="two" style="width: device-width; height: 150px;"></div>
<div id="three" style="width: device-width; height: 150px;"></div>
<div id="four" style="width: device-width; height: 150px;"></div>
<div id="five" style="width: device-width; height: 150px;"></div>
<div class="ui-select">
<select name="usageDropDownList" id="usageDropDownList"
data-native-menu="false" tabindex="-1">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
<option value="five">5</option>
</select>
</div</div>
这里是我的document.ready()
$(document).ready(function() {
$("#usageDropDownList").change(function() {
if ($(this).val() == 'one') {
$("#two").hide();
$("#three").hide();
$("#four").hide();
$("#five").hide();
$("#one").show();
} else if ($(this).val() == 'two') {
$("#one").hide();
$("#three").hide();
$("#four").hide();
$("#five").hide();
$("#two").show();
} else if ($(this).val() == 'three') {
$("#one").hide();
$("#two").hide();
$("#four").hide();
$("#five").hide();
$("#three").show();
} else if ($(this).val() == 'four') {
$("#one").hide();
$("#two").hide();
$("#three").hide();
$("#five").hide();
$("#four").show();
} else if ($(this).val() == 'five') {
$("#one").hide();
$("#two").hide();
$("#three").hide();
$("#four").hide();
$("#five").show();
}
});
});
任何一个可以建议我一个更好的办法?
@乔恩嗨,如果我写你的代码,然后我的下拉列表一也隐藏。我不想那样。我想要排除下拉列表。 :) – 2012-03-14 09:07:50
是的,使用的兄弟姐妹()选择不只是你要隐藏的div更多。 – jchavannes 2012-03-14 09:09:30
@Coder_sLaY:对不起。看看更新。 – Jon 2012-03-14 09:12:53