简体   繁体   English

jQuery星级评分问题

[英]jQuery star rating question

I have a around 8 jQuery star rating in my page: 我的页面上有大约8个jQuery星级:

<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 user clicks on the rating, it does a post back to the database (MySQL) and update some data. 我想做的是,当用户单击评分时,它将回发到数据库(MySQL)并更新一些数据。 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? 上例中的star2是哪个? 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. 要获得clicked元素的属性,您想使用.attr(string)函数。

$('.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. 编辑:我没有意识到该值是作为回调参数提供的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM