2

I have select box and when the options change it shows another select box and it works fine however I want to have radio button show instead of selectbox. 有人可以帮我吗?

 .sub{display:none;}

 <script type="text/javascript">
 var $sub = $('select.sub');
 $('select').first().change(function () {    
 $sub.hide();
 if (this.selectedIndex > 0)
   $sub.eq(this.selectedIndex - 1).show();
 }).change();
</script>

 <select><--!main select box--!>
 <option value="">select</option>
 <option> one</option>
 <option> two </option>
 </select>

 <select class="sub">
 <option> one 1</option>
 <option> one 2</option
 </select>

 <select class="sub">
 <option> two 1</option>
 <option> two 2</option>
 </select>

这是我需要的,而不是上面的两个选择框....

<div class="sub">
<input type="radio">one 1
<input type="radio">one 2
</div>

 <div class="sub">
<input type="radio">two 1
<input type="radio">two 2
</div>
4

1 回答 1

1

如果这是你想要的东西?

<select>
 <option value="">select</option>
 <option value="sub1"> one</option>
 <option value="sub2"> two </option>
 </select>

<div class="sub sub1">
<input type="radio">one 1
<input type="radio">one 2
</div>
<div class="sub sub2">
<input type="radio">two 1
<input type="radio">two 2
</div>


$('.sub').hide();

$('select').on('change', function(){
    $('.' + this.value).show();
});

工作演示

于 2013-09-05T02:20:10.757 回答