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);
});
}
});
});
主な問題は、ページに複数のノブがあることです。これらのノブは、実際にはワードプレスの投稿でループしています。
とにかく、各ノブは an に接続されてID
おり、これID
はループを通過するにつれて変化します。
スコアを更新できるようにするには、関数value
から取得する 2 つのノブと、ループ内でのみ取得できる が必要です。では、この関数の変数を取得するにはどうすればよいでしょうか?release
post_id
post_id
通常は、button
またはリンクを追加するだけで済みますonclick="my_function(<?php echo $post_id; ?>)
が、これではできません。このノブに対応する $id を取得し、パラメータとしてリリース関数に渡す最良の方法は何ですか?