获取所选的单选按钮值

Cur*_*der 3 jquery radio-button

$("#poll1p").append("<input type='radio' name='radio1' id='r1' /><label for='radio1'>"+x[0]+"</label><br>");
$("#poll1p").append("<input type='radio' name='radio1' id='r2' /><label for='radio1'>"+x[1]+"</label><br>");
Run Code Online (Sandbox Code Playgroud)

x[0]x[1]数组值.我无法通过使用获得所选的单选按钮值

$("input:radio[name='radio1']:checked").val();
Run Code Online (Sandbox Code Playgroud)

如果我使用上面的内容,我只是将"ON"作为返回值...我需要来自的值

mea*_*gar 7

value="..."如果您想要返回"on"之外的某些值,则需要为单选按钮指定属性.

使用以下内容,您应该回来12.val():

<input type='radio' name='radio1' id='r1' value="1" />
<input type='radio' name='radio1' id='r2' value="2" />
Run Code Online (Sandbox Code Playgroud)

不相关,但您还需要使用for="r1"for="r2"为您的标签 - 即,使用元素id作为for其标签的属性的值.