Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在触发colorbox时指定colorbox的href属性_Jquery_Colorbox - Fatal编程技术网

Jquery 在触发colorbox时指定colorbox的href属性

Jquery 在触发colorbox时指定colorbox的href属性,jquery,colorbox,Jquery,Colorbox,是否可以在单击触发colorbox的实际按钮时指定colorbox的目标URL 目前,我的文档绑定函数中有以下内容: $(function () { $(".button").colorbox({ width: "50%", height: "50%%", iframe: true, href: "/abc", opacity: 0.6 }); }); 但是,href属性取决于我第一次将colorbox绑定到按钮时不知道的下拉列表的值。如中所述 您可以设置回调“onOpen”(也可能设

是否可以在单击触发colorbox的实际按钮时指定colorbox的目标URL

目前,我的文档绑定函数中有以下内容:

$(function () {
    $(".button").colorbox({ width: "50%", height: "50%%", iframe: true, href: "/abc", opacity: 0.6 });
});
但是,href属性取决于我第一次将colorbox绑定到按钮时不知道的下拉列表的值。

如中所述

您可以设置回调“onOpen”(也可能设置为“onLoad”),在colorbox开始加载目标中指定的内容之前,应该触发回调,以便您有机会修改它

$(function () {
    $(".button").colorbox({ 
        width: "50%", 
        height: "50%%", 
        iframe: true, 
        href: "/abc", 
        opacity: 0.6,
        onOpen: function(){
          // modify target here
        }
    });
});
更新 可能更简单的解决方案-colorbox允许使用函数而不是静态值

$(function () {
    $(".button").colorbox({ 
        width: "50%", 
        height: "50%", 
        iframe: true, 
        href: function(){
            // Since I can't see your markup I can't provide exact solution
            // but if your .button elm is an anchor then use
            var url = $(this).attr('href');
            // if you are obtaining the url from diff. elm, grab it from there
            // such as $('#your_element).attr('href') 
            return url;
        }, 
        opacity: 0.6
    });
});

你可以这样做。。。这种方法绕过了插件的自动onClick处理。在确定要使用的href值后,您可以在自己的事件中调用插件

在下面的代码片段中,varmyHref是静态的,但是您可以编写一些js从数据源进行设置

顺便说一句,我想你在高度属性上有一个输入错误-重复%符号

<script>
        $(document).ready(function(){
            $('.button').click( function() {
                var myHref = "/someHREF";
                $.colorbox({
                    width: "50%", 
                    height: "50%", 
                    iframe: true, 
                    href: myHref, 
                    opacity: 0.6
                });             
            });
        });             
</script>

$(文档).ready(函数(){
$('.button')。单击(函数(){
var myHref=“/someHREF”;
$彩色盒({
宽度:“50%”,
身高:“50%”,
伊夫拉姆:是的,
href:myHref,
不透明度:0.6
});             
});
});             

Hi Peter,你如何在onOpen事件中指定URL?嗨Kevin,是的,你是对的。最简单的方法是让href属性从函数中获取其值:href:function(){return”/href“},添加了
e.preventDefault()用于
链接。