获取所有单选按钮值的总和以显示在表中 [英] Getting the sum of all radio button values to display in a table
本文介绍了获取所有单选按钮值的总和以显示在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表格中有一些单选按钮,我为它们设置了一个值。当用户选择它们并点击提交按钮时,我希望这些值的总和可以显示在另一个表格中。
< tr> < TD> < span id =Label1>显示天气情况?< / span> < / TD>< / TR>< TR> < TD> < table id =a1_1> < TBODY> < TR> < TD> < input type =radiovalue =1name =a1_1id =a1_1_0> < label for =a1_1_0>完美< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =2name =a1_1id =a1_1_1> < label for =a1_1_1>良好< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =3name =a1_1id =a1_1_2> < label for =a1_1_2>不坏< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =4name =a1_1id =a1_1_3> < label for =a1_1_3>坏< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =5name =a1_1id =a1_1_4> < label for =a1_1_4>很差< / label> < / TD> < / TR> < / tbody的> < /表> < / TD>< / TR>< TR> < TD> < span id =Label1>显示天气情况?< / span> < / TD>< / TR>< TR> < TD> < table id =a1_2> < TBODY> < TR> < TD> < input type =radiovalue =1name =a1_2id =a1_1_0> < label for =a1_2_0>完美< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =2name =a1_2id =a1_1_1> < label for =a1_2_1>良好< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =3name =a1_2id =a1_1_2> < label for =a1_2_2>不错< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =4name =a1_2id =a1_1_3> < label for =a1_2_3>坏< / label> < / TD> < / TR> < TR> < TD> < input type =radiovalue =5name =a1_1id =a1_1_4> < label for =a1_2_4>很差< / label> < / TD> < / TR> < / tbody的> < /表> < / td>< / tr>
解决方案首先,您需要获取选中的单选按钮的值
诀窍是让它像这样:
$(input [name ='a1_1']:checked)。val();
之后,您可以对值进行任何操作。
我希望这可以帮助你。
I have some radio buttons in a table and I’ve set a value to them. When the user selects them and clicks the submit button, I want the sum of those values to show in another table.
<tr>
<td>
<span id="Label1">hows the weather ?</span>
</td>
</tr>
<tr>
<td>
<table id="a1_1">
<tbody>
<tr>
<td>
<input type="radio" value="1" name="a1_1" id="a1_1_0">
<label for="a1_1_0">perfect</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="2" name="a1_1" id="a1_1_1">
<label for="a1_1_1">good</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="3" name="a1_1" id="a1_1_2">
<label for="a1_1_2">not bad</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="4" name="a1_1" id="a1_1_3">
<label for="a1_1_3">bad</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="5" name="a1_1" id="a1_1_4">
<label for="a1_1_4">very bad</label>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<span id="Label1">hows the weather ?</span>
</td>
</tr>
<tr>
<td>
<table id="a1_2">
<tbody>
<tr>
<td>
<input type="radio" value="1" name="a1_2" id="a1_1_0">
<label for="a1_2_0">perfect</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="2" name="a1_2" id="a1_1_1">
<label for="a1_2_1">good</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="3" name="a1_2" id="a1_1_2">
<label for="a1_2_2">not bad</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="4" name="a1_2" id="a1_1_3">
<label for="a1_2_3">bad</label>
</td>
</tr>
<tr>
<td>
<input type="radio" value="5" name="a1_1" id="a1_1_4">
<label for="a1_2_4">very bad</label>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
解决方案
First you need to get the value of the checked radio buttons
The trick is to get it like this:
$("input[name='a1_1']:checked").val();
Afterwards you can do whatever you want with the values.
I hope this helps you.
这篇关于获取所有单选按钮值的总和以显示在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文