I ha开发者_如何学JAVAve the following callback function when using the jQuery star plugin:
$('.star').rating({
callback: function (value, link) {
{
if (response.session) {
$.post("update.php", {
uid: response.session.uid,
mid: $('.star').attr('name'),
val: value
});
alert($('.star').attr('name'));
}
});
}
});
and the following html:
<input name="star2" type="radio" class="star"/>
<input name="star2" type="radio" class="star"/>
<input name="star2" type="radio" class="star" checked="checked"/>
<input name="star2" type="radio" class="star"/>
<input name="star2" type="radio" class="star"/>
how can I get the name from the jQuery? I tried doing .attr as above and it returns undefined. I tried doing $($this).attr('name')
and it returns the jquery fancy box name..
$('.star')
returns a collection of jQuery objects, so you should iterate it e.g.:
$('.star').each(function () {
alert($(this).attr('name'));
});
the checked element is found by:
$('.star:checked').attr('name');
update, (in reply to comments) for multiple groups:
what if I have two star rating sets
$('.star:checked').each(function () {
alert($(this).attr('name'));
});
var nameOfCheckedStar = $('.star:checked').attr('name');
I'm assuming you want the name of the checked star
精彩评论