我绝不是 javascript 程序员,所以如果有人能帮助我解决这个问题就太好了。如果在同一页面上有多个这样的评级部分,如下面的示例所示。
现在我需要将已单击的单选按钮的值发送到我的数据库,而不需要提交按钮,最好不要刷新。
<body>
<section class="rating">
<input type="radio" class="radio twenty" name="progress" value="twenty" id="twenty" <?php if($num === 1) { echo 'checked'; } ?>>
<label for="twenty" class="label">1</label>
<input type="radio" class="radio fourty" name="progress" value="fourty" id="fourty" <?php if($num === 2) { echo 'checked'; } ?>>
<label for="fourty" class="label">2</label>
<input type="radio" class="radio sixty" name="progress" value="sixty" id="sixty" <?php if($num === 3) { echo 'checked'; } ?>>
<label for="sixty" class="label">3</label>
<input type="radio" class="radio eighty" name="progress" value="eighty" id="eighty"<?php if($num === 4) { echo 'checked'; } ?>>
<label for="eighty" class="label">4</label>
<input type="radio" class="radio onehundred" name="progress" value="onehundred" id="onehundred" <?php if($num === 5) { echo 'checked'; } ?>>
<label for="onehundred" class="label">5</label>
<div class="progress">
<div class="progress-bar"></div>
</div>
</section>
</body>
我已经设置了检索选中的单选按钮,使其对应于 1 到 5 的评级,所以我目前正在使用测试数据来显示 1 到 5 的评级。
我不一定需要所有的细节,需要完成的步骤的概述已经非常有帮助了。
最佳答案
应该这样做
在jQuery include之后添加到头部 而且我把class改成了进度条的id
$(function() { // when document has loaded
$(".radio").on("click",function() { // all radios with class="radio ..."
// ajax get or post someserver.php?value=twenty/fourty...
$.get("someserver.php", {value:this.value},function(data) {
// add the returned value to a container
$("#progress-bar").append("Updated "+ data);
});
});
});
关于php - 没有提交的单选按钮值到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16277078/