2 回答

TA貢獻1828條經驗 獲得超3個贊
首先,最好用有意義的名稱來命名您的輸入。
例如
echo?'<td?width=100>?<input?type="radio"?name="score['.$i.']"??value="1"?>?</td>'
這將幫助您區分其他字段 - 如果您需要添加其他字段 -
在服務器端,您現在有一個名為 的輸入數組,您可以使用如下方法score
求和/計算總數:array_sum
if?(isset($_POST['score']))?{ ????$total?=?array_sum($_POST['score']); }
要保存該值,您可以使用session
this

TA貢獻1801條經驗 獲得超8個贊
您可以使用相同的單選按鈕但不同的值
<input type="radio" name="score" value="1" >
,<input type="radio" name="score" value="2" >
。在單選按鈕中傳遞自定義類,如下所示
<input type="radio" class="cstm-radio" name="score" value="1" >
;使用單擊java腳本或jquery事件來獲取單擊的單選按鈕的值并執行ajax請求,傳遞您必須在其中執行后端操作的文件的url或文件名。
您可以使用此代碼來執行ajax請求!
$('.cstm-radio').click(function () {
var radio_val = $(this).val();
$.ajax({
//url of your php file
url: "post.php",
type: "POST",
data: {score: radio_val},
success: function (data) {
// alert radio value here
alert(data);
}
});
});
- 2 回答
- 0 關注
- 214 瀏覽
添加回答
舉報