我google了很多我的requirement.So我發佈這個問題。 我的要求是當用戶從下拉列表中選擇一個值,根據該值顯示div。但在默認情況下,所有的div值都要顯示。如何顯示隱藏和顯示選擇框?
這裏是我的代碼:
<select name="lab_1" id="title" >
<option value="All" onclick="showAll();" >All</option>
<option value="one" onclick="showOther();">One</option>
<option value="two" onclick="showOther();">Two</option>
</select>
<div id="All" >
hiihdhfhdf
<div id="otherTitle" style="display:none;" >
select
</div>
<div id="otherTitle2" style="display:none;" >
ramsai
</div>
</div>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script>
$(function() {
$('#title').change(function() {
var all= $("#All").val();
alert('hi');
if(all==""){
$("#otherTitle").show();
$("#otherTitle2").show();
}
else if (this.value == "one") {
$("#otherTitle").show();
$("#otherTitle2").hide();
}
else if (this.value=="two"){
$("#otherTitle2").show();
$("#otherTitle").hide();
}
});
});
</script>
</body>
這裏與上面的代碼當我點擊我的所有的div都沒有顯示,但是當我去到一個或兩個選項則顯示所有的值。 我有42個div的一種適用於所有提到的那些是爲
唯一的解決方案預先感謝您
Ramsai的div jQuery中或低於任何其他解決方案
這是怎麼PHP? :) – mishu 2012-07-18 12:40:49
與此我使用PHP代碼也,但我沒有給這個問題,所以我把標籤作爲PHP – ramsai 2012-07-18 12:50:39
'div'元素('#所有')沒有價值,所以'$(「 #All「)。val()'will ** always **返回一個空字符串和'all =='''將**總是**爲** true **。我不明白你在做什麼 – 2012-07-18 12:50:58