2009-11-25 38 views
1
<script type="text/javascript"> 
var Average_rating = a number between 1 and 5 
</script> 
<select name="rate"> 
     <option value="1" class="p_rating_star" />Not so great</option> 
     <option value="2" class="p_rating_star" />Quite good</option> 
     <option value="3" class="p_rating_star" />Good</option> 
     <option value="4" class="p_rating_star" />Great!</option> 
     <option value="5" class="p_rating_star" />Excellent!</option> 
</select> 

我建立一個評級系統。如何在jQuery中做到這一點?這是關於類和添加一些東西到標籤

如何使用JQuery將「selected = selected」添加到其中一個選項值,具體取決於average_rating?

怎麼說呢......

Add "selected = selected" to anything with class "p_rating_star" where average_rating = that class's value (1-5)? 
+3

不相關的問題 - 你

回答

3
$(".p_rating_star[value=" + average_rating + "]").attr("selected", "selected"); 
1
$('[value=' + Average_rating + '].p_rating_star').attr('selected', 'selected'); 
相關問題