从JavaScript中的无线电输入获取值(5星级)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从JavaScript中的无线电输入获取值(5星级)相关的知识,希望对你有一定的参考价值。

Get value from 5 Star Rating
  1. //html:
  2. <form class="rating" method="post">
  3. <input type="radio" id="star5" name="rating" value="5" onclick="postToController();" /><label for="star5" title="Super !!">5 stars</label>
  4. <input type="radio" id="star4" name="rating" value="4" onclick="postToController();" /><label for="star4" title="Geil">4 stars</label>
  5. <input type="radio" id="star3" name="rating" value="3" onclick="postToController();" /><label for="star3" title="Gut">3 stars</label>
  6. <input type="radio" id="star2" name="rating" value="2" onclick="postToController();" /><label for="star2" title="So gut wie">2 stars</label>
  7. <input type="radio" id="star1" name="rating" value="1" onclick="postToController();" /><label for="star1" title="Schlecht">1 star</label>
  8. </form>
  9.  
  10.  
  11. function postToController() {
  12. for (i = 0; i < document.getElementsByName('rating').length; i++) {
  13. if(document.getElementsByName('rating')[i].checked == true) {
  14. var ratingValue = document.getElementsByName('rating')[i].value;
  15. break;
  16. }
  17. }
  18. alert(ratingValue);
  19. }

以上是关于从JavaScript中的无线电输入获取值(5星级)的主要内容,如果未能解决你的问题,请参考以下文章