【问题标题】:Colorbox query string href, adding dynamic ID?Colorbox查询字符串href,添加动态ID?
【发布时间】:2011-07-30 10:15:43
【问题描述】:

我已经对颜色框进行了编码,以便我可以使用 URL http://example.com?open=true 在颜色框内打开页面上的第一个图像。我想使用附加到颜色框链接的 id 添加标签,以便在颜色框中打开特定图像(不仅仅是页面上的第一张图像)。 URL 应如下所示:http://example.com?id=12345?open=true

我知道这对你们大多数人来说可能是小菜一碟,所以请帮助我,我正在努力学习。

这是我目前使用的彩盒代码:

$(document).ready(function(){
    var
    vars = [],
    hash,
    hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
    }
    $("a[rel='example1']").colorbox({open:vars['open'] == 'true' ? true : false});}); 

我对 jquery 了解不多,但我相当肯定有一种简单的方法可以将 ID 添加到自动打开的 URL?链接 ID 是通过 Wordpress 自动提供的,因此我无法手动将每个 ID 输入到 jquery 中。

这是图片链接的代码:

<a href="/images/exampleimage.jpg" rel="example1" id="<?php the_ID(); ?>">
<img src="images/exampleimagethumbnail.jpg" border="0"></a>

【问题讨论】:

    标签: jquery url hash href colorbox


    【解决方案1】:

    你在 vars['id'] 中有 id 那么为什么不这样做:

     $("a[id="+vars['id']+"]").colorbox({open:vars['open'] == 'true' ? true : false})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多