页面启动时自动显示的jquery颜色框

时间:2012-07-25 09:42:51

标签: jquery colorbox

如果存在查询字符串,如何让我的颜色框自动显示。 到目前为止,我有以下内容:

$(document).ready(function ()
{
    //if this is coming from continental
    if (document.location.href.indexOf("redirect=cfs") != -1)
    {
        //create box
        var $notice = $("<div>hello World</div>").appendTo($("body"));
        console.log($notice.text());
        $notice.colorbox({ inline: true, width: "965px" });
    }
});

但是这没有用,因为看起来你似乎需要触发colorbox来展示一些东西?

修改 我刚刚意识到您可以使用$.colorbox,但如何将我的内容添加到其中?

此致 雅克

2 个答案:

答案 0 :(得分:1)

只需使用colorbox的html属性:

$(document).ready(function (){
    if (document.location.href.indexOf("redirect=cfs") != -1)
    {
        var $notice = $("<div>hello World</div>");
        $notice.colorbox({ html: $notice, width: "965px" });
    }
});

答案 1 :(得分:0)

以下代码为我做了:

$(document).ready(function ()
{
    //if this is coming from continental
    if (document.location.href.indexOf("redirect=cfs") != -1)
    {
        //create box
        var $notice = $("<div id='partnerMove'>test</div>").appendTo($("body"));
        console.log($notice.text());
        **$.colorbox({ href: '#partnerMove', inline: true, width: "600px" });**
    }
});

因此,您可以动态创建HTML元素,然后使用{icon>}使用colorbox的 href 设置引用新元素。