簡體   English   中英

Javascript this.form.submit() 帶單選按鈕

[英]Javascript this.form.submit() with radio button

我的網頁有這個星級評分系統,您可以在其中選擇星級評分(1-5),我想在有人單擊任何星星時發送表單,但現在,如果出現以下情況,它不會發送單選按鈕值我檢查了一些東西,我認為這是因為它在檢查單選按鈕之前發送了表單。 有沒有更好的方法來發送帶有單選按鈕值 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>

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

 <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM