1

我绝不是 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 的评级,所以我目前正在使用 testdata 来显示 1 到 5 的评级。

我不一定需要所有细节,需要完成的步骤的概述已经非常有帮助。

4

3 回答 3

3

这应该这样做

演示

在 jQuery 包含之后将它添加到头部并且我将类更改为进度条的 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); 
    });
  });
});
于 2013-04-29T11:09:05.133 回答
2

您可以为此使用 AJAX。如果您使用的是 Jquery,则可以使用单击处理程序来检测您的元素单击并启动一个函数调用,该函数调用反过来可以调用 AJAX 函数与您的服务器端代码交互并将值发送到数据库中。

于 2013-04-29T11:07:12.740 回答
2
  • 将 onclick 或 onchange 操作添加到使用适当参数发送 ajax 请求的输入
  • 接收请求,验证数据
  • 插入/更新行
于 2013-04-29T11:08:05.443 回答