在javascript中使用id获取动态radiobutton? [重复]

时间:2022-12-05 12:03:13

This question already has an answer here:

这个问题在这里已有答案:

In my view i create a dynamic radio button the sample code of this is as follows..

在我看来,我创建了一个动态单选按钮,其示例代码如下所示。

 @for (int i = 0; i < Model.ChManufacturer.Count(); i++)
  {
     if (@Model.ChManufacturer[i].Text == "Select ...")
     {
     }
     else
     {
       <td>&nbsp;&nbsp;&nbsp;<input id="manufacturer:@Model.ChManufacturer[i].Text" type="radio" name="Manu_rbgrp" value="@Model.ChManufacturer[i].Text">&nbsp;@Model.ChManufacturer[i].Text
       </td>
     }
   }

but i am in need of get the selected radiobutton value. How to get the values of a checked radiobutton.. For Ex: O abc , O bbc, O ccc. So if i select the 2nd option means ithe value is bbc. Any answer??? i got the following output at the runtime

但我需要获得所选的radiobutton值。如何获得已检查的单选按钮的值。对于Ex:O abc,O bbc,O ccc。因此,如果我选择第二个选项意味着它的价值是英国广播公司。任何答案???我在运行时获得了以下输出

<td>
<input id="manufacturer:GLI-List" type="radio" value="GLI-List" name="Manu_rbgrp">
 GLI-List
</td>
<td>
<input id="manufacturer:Latham-List" type="radio" value="Latham-List" name="Manu_rbgrp">
 Latham-List
</td>
<td>
<input id="manufacturer:Loop-Loc-List" type="radio" value="Loop-Loc-List" name="Manu_rbgrp">
 Loop-Loc-List
</td>
<td>
<input id="manufacturer:Merlin-List" type="radio" value="Merlin-List" name="Manu_rbgrp">
 Merlin-List
</td>

1 个解决方案

#1


1  

Use the onclick event and store selected values in a JS object or array.
Example using of the onclick and getting the id of a radio: http://jsfiddle.net/coshmos/CBk5d/

使用onclick事件并将所选值存储在JS对象或数组中。使用onclick并获取收音机ID的示例:http://jsfiddle.net/coshmos/CBk5d/

Code of the examle:

考试代码:

<label>
<input id="SomeId" type="radio" onclick="alert(this.id);"/> Radio
</label>

#1


1  

Use the onclick event and store selected values in a JS object or array.
Example using of the onclick and getting the id of a radio: http://jsfiddle.net/coshmos/CBk5d/

使用onclick事件并将所选值存储在JS对象或数组中。使用onclick并获取收音机ID的示例:http://jsfiddle.net/coshmos/CBk5d/

Code of the examle:

考试代码:

<label>
<input id="SomeId" type="radio" onclick="alert(this.id);"/> Radio
</label>