2011-04-06 43 views
1

我已經編碼了colorbox,這樣我就可以使用url http://example.com?open=true在colorbox中打開頁面上的第一個圖像。我想使用附加到colorbox鏈接的id添加一個標籤,以便在colorbox(不僅僅是頁面上的第一個圖像)中打開特定圖像。網址應該如下所示:http://example.com?id=12345?open=trueColorbox查詢字符串href,添加動態ID?

我知道這對大部分人來說可能是一塊蛋糕,所以請幫助我,我正在努力學習。

這是我目前使用的顏色框代碼:

$(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添加到自動打開網址是什麼?鏈接ID是通過Wordpress自動給出的,所以我無法手動輸入每個ID到jQuery中。

下面是圖片鏈接代碼:

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

回答

0

您在瓦爾的ID [ '身份證'],爲什麼不只是做:

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