我有這麼多的聯繫:使用jQuery與HREF更換rel屬性 - 保值,
<a rel="custom_link1_to_large_image">thumb</a>
有沒有辦法保留鏈接,並有代替HREF: HREF =「custom_link1_to_large_image」
我需要讓它與Lightbox nad一起工作我無法像手動添加那樣由NextGen從WP自動生成。
謝謝!
我有這麼多的聯繫:使用jQuery與HREF更換rel屬性 - 保值,
<a rel="custom_link1_to_large_image">thumb</a>
有沒有辦法保留鏈接,並有代替HREF: HREF =「custom_link1_to_large_image」
我需要讓它與Lightbox nad一起工作我無法像手動添加那樣由NextGen從WP自動生成。
謝謝!
這應做到:
$('a[rel]').attr('href', function() {
return $('this').attr('rel');
}).attr('rel', '');
$("a").each(function(){
$(this).attr("href", $(this).attr("rel"));
});
以上將來自所有鏈接:
<a rel="custom_links">..</a>
成爲
<a rel="custom_links" href="custom_links">...</a>
我會做更是這樣的:
$('a[rel]').attr('rel',function(i,rel){ this.href = rel; return null; });
例子:http://jsfiddle.net/patrick_dw/xnyr5/
如果您想保留rel
,只是刪除return null;
。
謝謝,這看起來有點複雜,但它的工作。看其他答案,這些也應該工作。 – Lucian 2010-11-20 17:37:24
@Lucian - 不客氣。它可能看起來很複雜,因爲它在一條線上。用分行符分解函數的主體,它可能看起來更乾淨一點。如果你不想擺脫'rel'屬性,我會改變它[這個](http://jsfiddle.net/patrick_dw/xnyr5/1/):'$('a [rel]' ).attr('href',function(){return this.rel;});' – user113716 2010-11-20 17:44:23