我有一个PHP代码,如下所示:
$rate = "<div class='"example-'" href='"#'" onclick='"wallpost(".$id.")'"></div></br>;
jquery是这样的:
$('.example-').ratings(5).bind('ratingchanged', function(event, data) {
function wallpost(pass){
var a = pass;
}
$.post('count.php',{rate:data.rating,wallpostid :a},function(data){
alert(data);
});
});
当我给jquery打分时,我想传递$id值,然后通过使用$.post.将$id值和多少颗星打分传递给"count.php"
当我尝试上面的代码时,它无法评分。
我的问题是什么?
不需要wallpostid
方法
$rate = "<div class='"example-".$id." '" data-postid='"".$id."'"></div></br>Post id: <span class='"example-rating-".$id."'">".$id."</span>";
和
$('[class^="example-"]').not('[class^="example-rating-"]').ratings(3).bind('ratingchanged', function (event, data) {
var child = $(this).find('[class^="example-rating-"]');
child.text(data.rating);
$.post('count.php', {
rate: data.rating,
wallpostid: $(this).data('postid')
}, function (data) {
alert(data);
});
});