0
我正在尋找顯示/隱藏單選按鈕的內容,當我選擇一個按鈕,但我需要一個默認按鈕(說第一個)是默認的(並顯示內容),然後顯示從那裏隱藏內容。jQuery的顯示/隱藏單選按鈕的內容(默認選擇必須顯示內容)
目前,它們都默認隱藏在顯示器上:none。下面是HTML:
<div style="float:left; width:300px;">
<div style="float:left;">
<form name="form1" id="my_form" method="post" action="">
<div>
<label>
<input type="radio" name="group1" value="opt1" checked="checked" />
opt1</label>
</div>
<div>
<label>
<input type="radio" name="group1" value="opt2" />
opt2</label>
</div>
<div>
<label>
<input type="radio" name="group1" value="opt3" />
opt3</label>
</div>
<input type="submit" value="Submit" />
</form>
</div>
<div style="float:right; width:200px;">
<div id="opt1" class="desc">
<form>
First name:
<input type="text" name="FirstName" value="Mickey" />
<br />
Last name:
<input type="text" name="LastName" value="Mouse" />
<br />
</form>
</div>
<div id="opt2" class="desc">
<form>
<input type="checkbox" name="vehicle" value="Bike" />
I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" />
I have a car
</form>
</div>
<div id="opt3" class="desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus convallis commodo euismod. Morbi vitae libero erat, quis ultrices purus.</div>
</div>
</div>
這裏是jQuery的:在DOM準備
$(document).ready(function(){
$("input[name$=group1]").click(function() {
var test = $(this).val();
$(".desc").hide();
$("#"+test).show();
});
});
非常感謝wirey!像一個魅力工作:-) – user763460