我有一个颜色框,可以让用户选择图像。如何从颜色盒中获取文件名? (我注意到onClosed
功能。)
解决方案:
正如@Gummy 所建议的,我使用了 onComplete 函数,如以下代码所示:
“返回”页面:
<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
}
});
});
在颜色盒源中
var image_name_var = "dynamicaly_change_this_name.png";
$('#submit-or-use-button-id').click(function() {
$('#colorbox_return_hidden').val(image_name_var);
});
当 colorbox 打开时,您可以随时调用 element 方法来检索当前元素的 jQuery 对象。从那里您可以选择元素并访问 href 属性:
href = $.colorbox.element()[0].href;
此外,在任何回调中,执行上下文(“this”的值)都将是当前元素。因此,如果您想使用 onComplete 回调,您可以执行以下操作:
$('#example').colorbox({onComplete:function(){
href = this.href;
}});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)