我正在使用 jQuery Knob 插件https://github.com/aterrien/jQuery-Knob
现在,我有以下 jQuery Knob Initialization
loop
<input type="text" value="<?php echo $score; ?>" class="circle-rating" data-entryid="<?php the_ID(); ?>">
endloop
$(function() {
$(".circle-rating").knob({
'min':0,
'max':10,
'step':1,
'width':40,
'height':40,
'fgColor':"#F59B00",
'inputColor':"#F59B00",
'displayPrevious': true,
'release' : function (v) {
var entry_id = $(this).attr('data-entryid');
jQuery.post("/path/to/file/update_library_score.php", {v : v, entry_id : entry_id}, function(data) {
console.log(entry_id);
jQuery('#notification-general').html(entry_id);
});
}
});
});
主要问题是我在页面上有多个旋钮。这些旋钮实际上与 wordpress 帖子循环在一起。
无论如何,每个旋钮都连接到一个ID
,并且ID
随着循环的进行而变化。
现在为了能够更新分数,我需要value
从release
函数中获得的两个旋钮,我还需要post_id
我只能在循环中获得的旋钮。那么我怎样才能得到post_id
这个函数的变量呢?
通常我可以简单地添加一个button
或一个链接,onclick="my_function(<?php echo $post_id; ?>)
但是我不能这样做。获取与此旋钮对应的 $id 并将其作为参数传递给释放函数的最佳方法是什么?