私は自分の要件のために多くのことをグーグルで調べています。だから私はこの質問を投稿しています。私の要件は、ユーザーが表示される 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 をクリックすると表示されませんが、1 つまたは 2 つのオプションに移動すると、すべての値が表示されます。私は42個のdivを持っています。jqueryのこれらすべてのdivに対する他の解決策はありますか、または以下で言及されているのはそのための唯一の解決策です
前もって感謝します
ラムサイ