I found 这个答案 https://stackoverflow.com/a/5674985/538786,这太棒了。但是如果我还必须在该元素周围包裹另一个元素怎么办?这就是我现在正在做的:
$('#screenshots').append($('<a href="' + link + '" title="' + title + '"><img src="' + el + '" alt="" width="200px" height="200px"></a>'));
有更好的方法吗?
如果你真的对纯粹的速度感兴趣,那么纯 DOM 方法将很难被击败:
var div = document.getElementById("screenshots"), anchor, img;
if (div) {
anchor = document.createElement("A");;
anchor.href = link;
anchor.title = title;
img = document.createElement("IMG");
img.src = el;
img.alt = "";
img.width = 200;
img.height = 200;
anchor.appendChild(img);
div.appendChild(anchor);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)