改变元素之间的来源

时间:2016-07-12 07:40:41

标签: javascript jquery

我正在寻找一种方法,用源元素中的链接替换目标元素中的链接。我知道如何在匹配链接时执行此操作 - 但是当我不知道使用链接类链接时,我该如何动态执行此操作?

<a class="target"><img src="http://example.com/wp-content/uploads/cache/remote/i3-ytimg-com/184998082.jpg" height="280" width="280" style="width: 100%; height: auto; display: block; margin-left: auto; margin-right: auto;"></a>

<a class="source"><img src="http://example.com/wp-content/uploads/cache/remote/i3-ytimg-com/100.jpg" height="280" width="280" style="width: 100%; height: auto; display: block; margin-left: auto; margin-right: auto;"></a>

1 个答案:

答案 0 :(得分:0)

这应该可行,请尝试一下,最后我可以修复代码

$(".target")
    .children("img")
        .attr("src",
            $(".source").children("img").attr("src")
        )