2012-06-04 31 views
0

我試圖在標題中放置一個鏈接,該鏈接基本上是選定的錨點href,並帶有前綴。我怎麼能做到以下幾點?我希望能夠在選定的錨元素上獲得this.href。Fancybox中的目標href

$(".gallery-module > li > a").fancybox(
{ 
    title  : '<a href="'+ this.href + '-large">DOWNLOAD</a><br> High Resolution File, 300dpi' 
}); 
+0

問題是怎麼回事,怎麼了? –

+0

this.href返回undefined – JCraine

+0

你有[現場演示代碼](http://jsfiddle.net/),我們可以看到和玩? –

回答

0

當你綁定的fancybox:

$(".gallery-module > li > a").fancybox({ 
    title: '<a href="'+ this.href + '-large">DOWNLOAD</a><br> High Resolution File, 300dpi' 
}); 

this不匹配<a>元素,this可能是window所以this.href不是<a>href屬性,this.href是(可能)window.href這並不是你想要的標題。

如果你想在的fancybox使用來自鏈接信息,你就可以遍歷集合使用each匹配的元素,並分別結合的fancybox每個<a>

$('.gallery-module > li > a').each(function() { 
    // 'this' will be the <a> in here 
    $(this).fancybox({ 
     title: '<a href="'+ this.href + '-large">DOWNLOAD</a><br> High Resolution File, 300dpi' 
    }); 
}); 

裏面$('.gallery-module > li > a').each回調, this將是您要查找的<a>

0

我假設你正在使用fancybox v1.3.x,不是嗎?

使用該版本,除非它在回調函數內,否則不能直接引用this.href。你的情況,你可以使用titleFormat選項自定義標題像

$(".gallery-module > li > a").fancybox({ 
titleFormat: function(){ 
    return '<div class="newTititleWrap"><a href="'+ this.href + '-large">DOWNLOAD</a><br> High Resolution File, 300dpi</div>' 
} 
}); 

注意,我裹在DIV定製的冠軍 = newTititleWrap(或任何你喜歡的),你可以樣式使用css後上。

UPDATE:我錯過了標籤fancybox-2(我的壞)。對於的fancybox v2.0.6使用像beforeShow回調選項:

$(".gallery-module > li > a").fancybox({ 
    beforeShow : function() { 
    this.title = '<div class="newTititleWrap"><a href="'+ this.href + '-large">DOWNLOAD</a><br> High Resolution File, 300dpi</dv>'; 
    } 
}); // fancybox 

我會讓張貼V1.3.4解決方案的情況下,它可以幫助別人。

+0

你是對的,我錯過了標籤「fancybox-2」(我的壞)...將編輯答案。 – JFK