在jQuery中試着隱藏/顯示,我可以得到第一個工作,但當我嘗試第二個我進入功能,可以看到過去的價值,但它什麼也沒做(實際上隱藏了第一個div)兩個jQuery的切換到目前爲止它
下面是第一個我的jquery。跟着我的HTML。正如你所看到的,我有兩個警報,並且我進入了他們兩個,但第二個。什麼都沒發生。
// SHOW/HIDE CONTENT
$(function() {
// SHOW HIDE FURNITURE TYPE SECTIONS
$("[name=radioShow]").click(function(){
alert('First to here!');
$('.toHide').hide();
$("#block-"+$(this).val()).show('slow');
});
// SHOW HIDE FOAM REPLACEMENT SECTION
$("[name=radioShowFoam]").click(function(){
alert('Second should show sommat!');
alert($(this).val());
$('.toHide').hide();
$(".foam-"+$(this).val()).show('slow');
});
});
現在下面是我的html。
<!--TYPE OF CHAIR-->
<div id="radio">
<input type="radio" id="radio1" name="radioShow" value="1"><label for="radio1">Dining Chair</label>
<input type="radio" id="radio2" name="radioShow" value="2"><label for="radio2">Stool</label>
<input type="radio" id="radio3" name="radioShow" value="3"><label for="radio3">Ottoman</label>
<input type="radio" id="radio4" name="radioShow" value="4"><label for="radio4">Louis XV style</label>
</div>
<!--DINING CHAIR SECTION-->
<div id="block-1" class="toHide" style="display:none; width:100%;">
<!--BASIC CHARGE FOR A DINING CHAIR IS FIRSTLY ADDED TO THE TEXT BOX BELOW-->
Price:<input id='text' value='10' />
<!--BELOW CODE WILL CALL THE FUNCTION TO TAKE THE VALUE OF WHATEVER HAS JUST BEEN CLICKED-->
<!--onchange='go(this.options[this.selectedIndex].value);-->
<h2>Dining Chair</h2>
<div class="radio">
<label class="orderLabel">Is the base Removable?</label>
<input type="radio" id="radio5" name="radio" value="y"><label for="radio5">Yes</label>
<input type="radio" id="radio6" name="radio" value="n"><label for="radio6">No</label>
</div>
<div class="radio">
<label>Number of removable bases/squabs per chair?</label>
<input type="radio" id="radio7" name="radio1" value="1"><label for="radio7">1</label>
<input type="radio" id="radio8" name="radio1" value="2"><label for="radio8">2</label>
</div>
<div class="radio">
<label for="spinner">Number of chairs:</label>
<input id="spinner" name="value"><button id="setvalue">Set value to 0</button><br />
</div>
<div class="radio">
<label>Foam replacement required?</label>
<input type="radio" id="radio09" name="radioShowFoam" value="1"><label for="radio09">Yes</label>
<input type="radio" id="radio10" name="radioShowFoam" value="0"><label for="radio10">No</label>
</div>
<!--IF YES-->
<div class="foam-1 toHide" style="display:none; width:100%;">
NEED FOAM
</div>
<!--END OF IF YES-->
<!--IF NO-->
<div id="foam-no" class="toHide" style="display:none; width:100%;">
DONT NEED FOAM
</div>
<!--END OF IF NO-->