jQuery barrating.js–发送id数据
我经常在一张桌子上为人们设定几个等级。一切都正常,除了我不能 select的data属性中的相应值将传递到评级函数,以便为正确的人员保存评级jQuery barrating.js–发送id数据,jquery,rating,jquery-bar-rating,Jquery,Rating,Jquery Bar Rating,我经常在一张桌子上为人们设定几个等级。一切都正常,除了我不能 select的data属性中的相应值将传递到评级函数,以便为正确的人员保存评级 $('.rating').each(function(index, value) { var dataId = $(this).closest('select').attr("data-rating-candidate"); //console.log(dataId); $('.rating').barrating('show',
$('.rating').each(function(index, value) {
var dataId = $(this).closest('select').attr("data-rating-candidate");
//console.log(dataId);
$('.rating').barrating('show', {
theme: 'bars-1to10',
onSelect: function(rating, text, event) {
if (typeof(event) !== 'undefined') {
console.log( dataId );
}
}
});
});
显然,只有属性中最后传递的值才用于dataId变量。那么,我如何获得所选评级的正确值呢?我似乎无法在弹幕选择中使用$this?您不能使用$this。但是在onSelect回调中有一个名为“this”的变量。例如,我的元素具有“data shop id”属性,然后我可以通过执行以下操作在onSelect中访问它的值:
onSelect: function(value, text, event) {
var el = this;
var shop_id = el.$elem.data('shop-id');
//do your stuff here
}
你不能用这个。但是在onSelect回调中有一个名为“this”的变量。例如,我的元素具有“data shop id”属性,然后我可以通过执行以下操作在onSelect中访问它的值:
onSelect: function(value, text, event) {
var el = this;
var shop_id = el.$elem.data('shop-id');
//do your stuff here
}