带有单选按钮的 Javascript this.form.submit()

标签 javascript php html

我的网页有这个星级评定系统,您可以在其中选择星级 (1-5),我想在有人点击任何一颗星时发送表格,但现在,它不发送 radio 按钮值如果我检查某些东西,我认为它是因为它在检查单选按钮之前发送表单。有没有更好的方法来发送带有单选按钮值 onclick 的表单?

<form method="POST" action="/rating" accept-charset="UTF-8"><input name="_token" type="hidden" value="vySkIFDPujcmxjfs83m3OwojcbPIaHuuMhKvVErx">

        <input name="movie_id" type="hidden" value="2">


        <input id="star5" name="rating" type="radio" value="5">
        <label for="star5" class="full" title="Awesome" onclick="this.form.submit()"> </label>


        <input id="star4" name="rating" type="radio" value="4">
        <label for="star4" class="full" title="Good" onclick="this.form.submit()"> </label>


        <input id="star3" name="rating" type="radio" value="3">
        <label for="star3" class="full" title="Mediocre" onclick="this.form.submit()"> </label>


        <input id="star2" name="rating" type="radio" value="2">
        <label for="star2" class="full" title="Bad" onclick="this.form.submit()"> </label>


        <input id="star1" name="rating" type="radio" value="1">
        <label for="star1" class="full" title="Horrible" onclick="this.form.submit()"> </label>

        </form>

最佳答案

使用 onchange<input /> 上元素代替:

<form method="POST" action="/rating" accept-charset="UTF-8"><input name="_token" type="hidden" value="vySkIFDPujcmxjfs83m3OwojcbPIaHuuMhKvVErx">

  <input name="movie_id" type="hidden" value="2">

  <label for="star5" class="full" title="Awesome">
<input id="star5" name="rating" type="radio" value="5" onchange="this.form.submit()">
  </label>

  <label for="star4" class="full" title="Good">
<input id="star4" name="rating" type="radio" value="4" onchange="this.form.submit()">
  </label>

  <label for="star3" class="full" title="Mediocre">
<input id="star3" name="rating" type="radio" value="3" onchange="this.form.submit()">
  </label>

  <label for="star2" class="full" title="Bad">
<input id="star2" name="rating" type="radio" value="2" onchange="this.form.submit()">
  </label>

  <label for="star1" class="full" title="Horrible">
<input id="star1" name="rating" type="radio" value="1" onchange="this.form.submit()">
  </label>

</form>

关于带有单选按钮的 Javascript this.form.submit(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54796420/

相关文章:

javascript - 返回两个对象之间的差异

php - 链接两个php动态下拉列表

javascript - 如果 2 个选择框匹配并自动选择第二个选项不匹配,我如何让它们相互关闭?

html - float : left and right inline without width 之间的 CSS 中心

用于插入查询的 PHP XML 数据

html - 普通和移动浏览器中图片后面的 Div 栏

javascript - 未选中 ng-repeat 列表中的复选框时禁用按钮

javascript - JS 类列表删除

javascript - 如何将函数设置为需要匿名函数的属性的值

php - 检查 PHP 类完整性的方法