![](/img/trans.png)
[英]Sum the value of radio buttons and print it to the respected textbox using JavaScript or jQuery
[英]How to change the value of radio buttons using Javascript/Jquery
說我有這個收音機:
<form name="myForm">
<input type="radio" name="foo" value="1"> 1
<input type="radio" name="foo" value="2"> 2
</form>
我正在尋找一種方法來做這樣的事情:
document.myForm.foo.value = "2";
為了動態選擇第二個單選按鈕。 或使用jquery執行以下操作的方法。
jQuery選擇器:
$('input[value="2"][name="foo"]')
用這個:
$('[name="foo"]').val(2);
由於您請求的是這種方式,因此您可以執行以下操作:
document.myForm.foo[1].checked = true; //selects the 2nd radio button
這是一個示例: http : //jsfiddle.net/bTzqw/
您是否正在尋找類似$(':radio[name=foo]:eq(1)')
如果您按名稱收集了jQuery集合中的所有無線電,則可以使用eq()
通過索引進行選擇。
$('input[name="foo"]').eq(1) // 2nd input
document.getElementsByName('foo')[1].check();//Or .checked = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.