选择后的每个单选按钮都有自己的选择选项,请参阅下面的代码。
使用 jQuery,有人可以帮我让它工作吗?
<HEAD>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$('#machines input:radio').change(function() {
var selectedVal = $("#machines input:radio:checked").val();
if(1 == selectedVal){
var bikeList = '<select name="Bikes"><option>Ducati</option><option>Kawasaki</option></select>';
$('select').remove();
$('#selectList').append(bikeList);
}else if(2 == selectedVal){
var carList = '<select name="Cars"><option>Audi</option><option>Nissan</option></select>';
$('select').remove();
$('#selectList').append(carList);
}
});
</script>
</HEAD>
<BODY>
<div id="machines">
<input type="radio" name="category" value="1" />Bikes
<input type="radio" name="category" value="2" />Cars
</div>
<div id="selectList"></div>
</BODY>