你如何从彩盒中获得回报价值? [英] How do you get a return value from a colorbox?

查看:69
本文介绍了你如何从彩盒中获得回报价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个让用户选择图像的颜色框。如何从彩盒中取回文件名? (我注意到 onClosed 函数。)

I have a colorbox that lets the user select an image. How do I get the file name back from the colorbox? (I have noticed the onClosed function.)

由于@Gummy sugested我使用了onComplete函数,如下面的代码所示:

As @Gummy sugested i used the onComplete function as the following code exemplifies:

<input id="colorbox_hidden_return" type="hidden"/>

...

$("#whatever-you-want-to-click-on-to-get-the-color-box").click(function() {
        $.colorbox(
        {
            href: '<?= site_url('the-source-url') . '/' ?>' + id, 
            height: "600px;", 
            onClosed: function() { // called when the colorbox closes
                var image = $('#colorbox_return_hidden').val();

                // ... other processing - what ever the value was is in image
            }   
        });
    });



在彩盒源



In the colorbox source

var image_name_var = "dynamicaly_change_this_name.png";

$('#submit-or-use-button-id').click(function() {
    $('#colorbox_return_hidden').val(image_name_var);
});


推荐答案

任何时候彩盒打开时,你都可以打电话给element方法,用于检索当前元素的jQuery对象。从那里你可以选择元素,并访问href属性:

Any time while colorbox is open, you can call the element method to retrieve a jQuery object of the current element. From there you can select the element, and access the href property:

href = $.colorbox.element()[0].href;

此外,在任何回调中,执行上下文('this'的值)将是当前元素。因此,如果您想使用onComplete回调,例如,您可以执行以下操作:

Also, in any callback the execution context (the value of 'this') will be the current element. So if you wanted to use the onComplete callback for example, you could do something like this:

$('#example').colorbox({onComplete:function(){
    href = this.href;
}});

这篇关于你如何从彩盒中获得回报价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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