0

I'm using jQuery raty for a personal website. I have a form and raty generates the following for each set of stars

<input type="hidden" name="score" value="5"> 

where value contains the values I want to get.

I have 10 fields with 5 stars each, and I want to get all 10 ratings with PHP/POST to insert into database.

What do I do about the fact that the inputs have the same name? I am aware that if it was name="score[]" I could access the ratings in an array, but I don't think I can change the name that raty assigns to inputs

4

1 回答 1

1

如果你不能改变老鼠的名字,这应该对你有帮助

HTML

<input type="hidden" name="score" value="5"> 
<input type="hidden" name="score" value="5"> 
<input type="hidden" name="score" value="5"> 

jQuery

    $(document).ready(){
      var score;
      $('input[name="score"]').each(function(index) {
        //YOUR LOGIC
        //IE: score = $(this).val(); console.log(score);
        //IE: POPULATE hidden submit form or store for AJAX call

      });          

});

但是,如果您可以添加一个类,那可能是更好的做法

HTML

<input type="hidden" class='score' name="score" value="5"> 
<input type="hidden" class='score' name="score" value="5"> 
<input type="hidden" class='score' name="score" value="5"> 

jQuery

    $(document).ready(){
      var score;
      $('.score').each(function(index) {
        //YOUR LOGIC
        //IE: score = $(this).val(); console.log(score);
      });

});

或者玩一个父 div id 和child()方法

于 2013-11-13T00:39:01.297 回答