Boris Callen..
11
更新
没有jquery的答案:https://stackoverflow.com/a/887348/11333
早在2009年,使用jquery完全可以接受:)
使用以下内容创建一个js文件:
$(document).ready(function() {
$('.threeimages').each(function(){
$(this).DupeHref();
});
});
jQuery.fn.DupeHref = function(){
var target = $(this).find(".text h2 a").attr("href");
$(this).find("a").attr("href", target);
}
在你的html中引用jquery和这个javascript文件.像这样的东西:
Test
Land of the sunshine!
Land of beer and food!
$来自jquery.确保导入jquery库.永远不会有多个具有相同ID的节点.要么你必须给它们唯一的id,要么你必须删除id并使用类.可以更改脚本以接受三个图像分类的节点,并且仅在该节点中工作. (2认同)