开发者

jQuery star rating question

开发者 https://www.devze.com 2023-02-28 01:35 出处:网络
I have a around 8 jQuery star rating in my page: <input class= \"auto-submit-star\" name=\"star2\" type=\"radio\" class=\"star\"/>

I have a around 8 jQuery star rating in my page:

<input class= "auto-submit-star" name="star2" type="radio" class="star"/>
<input class= "auto-submit-star" name="star2" type="radio" class="star"/>
<input class= "auto-submit-star" name="star2" type="radio" class="star" checked="checked"/>
<input class= "auto-submit-star" name="star2" type="radio" class="star"/>
<input class= "auto-submit-star" name="star2" type="radio" class="star"/>

What I want to do is that when a us开发者_开发知识库er clicks on the rating, it does a post back to the database (MySQL) and update some data. I know there is a callback function for this star rating that looks something like this:

$('.auto-submit-star').rating({
    callback: function(value, link){
        $.post("ajax.php", {name: unknown, val: value});
    }
})

The question is that in this callback function, how do I get the name. Which is star2 in the example above? Can someone also give me an example of a doing a post

;


To get an attribute of the clicked element you want to use the .attr(string) function.

$('.auto-submit-star').rating({
    callback: function(value, link){
        $.post("ajax.php", {name: unknown, val: $(this).attr('name')});
    }
})

EDIT: I didn't realize the value was provided as a callback param.

0

精彩评论

暂无评论...
验证码 换一张
取 消