HTML等价物:
<a href='#'> <img src='...'....../></a>
寻找以下内容:
var im = document.createElement("img");
im.ADDLINK;
相关代码:
var close = document.createElement("img");
close.src="close.png";
close.width = 50;
close.height = 50;
close.border = 1;
close.className="closeButton";
close.style.cssFloat="right";
var link = document.createElement("a");
link.href = "#";
将近距离图像设为链接:
link.appendChild(close);
close.style.right=0+"px";
//Div img is a div created above this code snippet:
divimg.appendChild(close);
答案 0 :(得分:3)
创建链接:
var link = document.createElement(a);
link.href = "http://...com";
添加图片:
var im = document.createElement("img");
link.appendChild(im);
并将其附加到需要的DOM
答案 1 :(得分:0)
你可以试试这个
<script>
function imgRedirect(destination){
location.href = destination;
}
</script>
<img src="..." onclick="imgRedirect('http://google.com')"/>