我有这个由javascript文件创建的HTML代码,这是不可理解的,因为它是使用GWT(Google Web Toolkit)创建的.
<img style="z-index: 6; width: 116px; position: absolute; left: 84px; top: 174px;" src="spiral/sample9.jpg">
<img style="z-index: 12; width: 197px; position: absolute; left: 0px; top: 161px;" src="spiral/sample1.jpg">
<img style="z-index: 1; position: absolute; left: 659px; top: 213px; width: 85px; opacity: 0.04; display: none;" src="spiral/sample17.jpg">
<img style="z-index: 1; position: absolute; left: 644px; top: 208px; width: 85px; opacity: 0.08; display: none;" src="spiral/sample18.jpg">
Run Code Online (Sandbox Code Playgroud)
现在我需要<a>在每个图像之前添加标记,使用as作为图像的src一部分src.例如:" href="../tmp.php?title=sample9.mp4"
任何线索我怎么能这样做?
我想要创建的输出是这样的:
<a href="../tmp.php?title=sample9.mp4"><img style="z-index: 6; width: 116px; position: absolute; left: 84px; top: 174px;" src="spiral/sample9.jpg"></a>
Run Code Online (Sandbox Code Playgroud)
使用jQuery,您可以使用wrap()这样做:
$('img').each(function() {
$(this).wrap($('<a/>', {href: this.src}));
});
Run Code Online (Sandbox Code Playgroud)