我的 HTML 和 JQuery 代码如下:
<form action="" method="post" id="myform">
<table border="0" class="table table-striped">
<tr>
<td colspan="7"><div class="title">CONNAISSANCE ET EXPERIENCE (O/E/AM/Cadres)</div></td>
</tr>
<tr>
<td></td>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>
<ul type="circle">
<li>1. Des techniques et pratiques du métier</li>
</ul>
</td>
<td></td>
<td><input type="radio" class="validate[required] radio" name="number1" id="number1" value="1"></td>
<td><input name="number1" class="validate[required] radio" type="radio" id="number1" value="2"></td>
<td><input name="number1" class="validate[required] radio" type="radio" id="number1" value="3"></td>
<td><input name="number1" class="validate[required] radio" type="radio" id="number1" value="4"></td>
<td><input name="number1" class="validate[required] radio" type="radio" id="number1" value="5"></td>
</tr>
<tr>
<td>
<ul type="circle">
<li>2. Capacité d’apprentissage et d’adaptation</li>
</ul>
</td>
<td></td>
<td><input class="validate[required] radio" type="radio" name="number2" value="1"></td>
<td><input class="validate[required] radio" name="number2" type="radio" value="2"></td>
<td><input class="validate[required] radio" name="number2" type="radio" value="3"></td>
<td><input class="validate[required] radio" name="number2" type="radio" value="4"></td>
<td><input class="validate[required] radio" name="number2" type="radio" value="5"></td>
</tr>
<tr>
<td><ul type="circle">
<li>3. Productivité/Rendement</li>
</ul></td>
<td></td>
<td><input class="validate[required] radio" type="radio" name="number3" value="1"></td>
<td><input class="validate[required] radio" name="number3" type="radio" value="2"></td>
<td><input class="validate[required] radio" name="number3" type="radio" value="3"></td>
<td><input class="validate[required] radio" name="number3" type="radio" value="4"></td>
<td><input class="validate[required] radio" name="number3" type="radio" value="5" /></td>
</tr>
<tr>
<td><ul type="circle">
<li>4. Polyvalenc</li>
</ul></td>
<td></td>
<td><input class="validate[required] radio" type="radio" name="number4" value="1"></td>
<td><input class="validate[required] radio" name="number4" type="radio" value="2"></td>
<td><input class="validate[required] radio" name="number4" type="radio" value="3"></td>
<td><input class="validate[required] radio" name="number4" type="radio" value="4"></td>
<td><input class="validate[required] radio" name="number4" type="radio" value="5"></td>
</tr>
<tr>
<td colspan="7">
<script>
$(document).ready(function(){
$("#test").click(function(){
var number1 = $('input[name=number1]:checked', '#myform').val();
var number2 = $('input[name=number2]:checked', '#myform').val();
var number3 = $('input[name=number3]:checked', '#myform').val();
var number4 = $('input[name=number4]:checked', '#myform').val();
var t1 = parseInt(number1);
var t2 = parseInt(number2);
var t3 = parseInt(number3);
var t4 = parseInt(number4);
var total = t1+t2+t3+t4;
alert (total);
});
});
</script>
<button name="btn" id="test">test</button>
</td>
</tr>
</table>
<form>
我需要: 当我点击每个单选框然后我点击按钮提交时,它将汇总单选框的所有值并显示它。
问题
我只能提醒总和值,但无法正常显示。示例:当我想显示我总是使用的值时的 PHP 代码,echo
但对于 JQuery 我还不知道。所以请任何人帮助我。给我一些想法,我应该使用像这样的 JQuery 还是比在这种情况下更好的 PHP。谢谢。