-1

I have a radio button with two possibility like following :

<input type="radio" name="radiobutton" value="first">
<input type="radio" name="radiobutton" value="second">

And i would like to synchronise with the following select :

<select name="myselect">
<option value="">Null default value</option>
<option>First value in select</option>
<option>Second value in select</option>
</select>

So - when i check first in radio button i would like that first element is automatically selected. - when i check second in radio button i would like that second element is automatically selected.

Besides, i would like to reset all values (of select and radiobutton) if an other select like following :

<select name="myresetselect">
<option value="">Null default value</option>
<option>First value in select</option>
<option>Second value in select</option>
</select>

...has first ('Null default value') selected.

4

1 回答 1

1

为选择选项添加与收音机中相同的值。这应该可以工作。

尝试这个

html

<select name="myselect">
  <option value="">Null default value</option>
  <option value="first">First value in select</option> //value should always be same as radios value
  <option value="second">Second value in select</option>
 </select>

jQuery

 $('input[name="radiobutton"]').click(function(){
     var val=$(this).val();
     $('select[name="myselect"]').val(val);
 });

在这里摆弄

拨弄重置按钮

不知道为什么你需要重置选择,而你可以使用简单的按钮......

例如:

<input type="button" value="Reset" id="resetbutton"/>

$('#resetbutton').click(function(){
 $('select[name="myselect"]').val("");
 $('input[name="radiobutton"]').prop('checked',false);
});
于 2013-07-09T09:29:38.007 回答