【发布时间】:2010-11-21 00:46:37
【问题描述】:
我有更多的链接,例如:
<a rel="custom_link1_to_large_image">thumb</a>
有没有办法保留链接并改为使用href: href="custom_link1_to_large_image"
我需要让它与灯箱一起工作,但我无法手动添加它,因为它是由 NextGen 从 WP 自动生成的。
谢谢!
【问题讨论】:
标签: jquery attributes href
我有更多的链接,例如:
<a rel="custom_link1_to_large_image">thumb</a>
有没有办法保留链接并改为使用href: href="custom_link1_to_large_image"
我需要让它与灯箱一起工作,但我无法手动添加它,因为它是由 NextGen 从 WP 自动生成的。
谢谢!
【问题讨论】:
标签: jquery attributes href
$("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('href', function() {
return $('this').attr('rel');
}).attr('rel', '');
【讨论】:
我会这样做:
$('a[rel]').attr('rel',function(i,rel){ this.href = rel; return null; });
示例: http://jsfiddle.net/patrick_dw/xnyr5/
如果您想保留rel,只需删除return null;。
【讨论】:
rel 属性,我会更改它to this:$('a[rel]').attr('href',function(){return this.rel;});