jQuery旋钮释放功能附加参数 [英] jQuery Knob Release function additional parameter

查看:164
本文介绍了jQuery旋钮释放功能附加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Knob插件 https://github.com/aterrien/jQuery-Knob

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

现在,我有以下jQuery旋钮初始化

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);

                });
            }

    });
});

主要问题是我在页面上有多个旋钮.这些旋钮实际上与wordpress帖子成环.

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

无论如何,每个旋钮都附在ID上,并且随着循环的进行,该ID会改变.

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

现在,要能够更新乐谱,我需要从release函数获得的旋钮value两件事,并且还需要只能在循环内获得的post_id.那么如何将post_id变量用于此功能?

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?

通常,我可以简单地添加button或带有onclick="my_function(<?php echo $post_id; ?>)的链接,但是我不能这样做.抓住与此旋钮对应的$ id并将其作为参数传递给release函数的最佳方法是什么?

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?

推荐答案

在发布功能中尝试

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

参见演示此处

这篇关于jQuery旋钮释放功能附加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆