jQuery Knob Release function additional parameter

冷暖自知 提交于 2019-12-12 05:37:08

问题


I'm using the jQuery Knob plugin https://github.com/aterrien/jQuery-Knob

Now, I've got the following 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);

                });
            }

    });
});

The main issue is that I have multiple knobs on the page. These knobs are actually in a loop with wordpress posts.

Anyway, each knob is attached to an ID and this ID changes as you go through the loop.

Now to be able to update the score I need two things the knob's value which I get from the release function and I also need the post_id which I can only get within the loop. So how can I get the post_id variable to this function?

Usually I can simply add a button or a link with a onclick="my_function(<?php echo $post_id; ?>) however, I can't do it with this. What's the best way of grabbing the $id that corresponds with this knob and passing it to the release function as a parameter?


回答1:


Try this in release function

alert(this.$.attr('data-entryid'));

See demo here



来源:https://stackoverflow.com/questions/20856236/jquery-knob-release-function-additional-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!