如何为使用以下javascript创建的图像添加链接.
感谢您的任何帮助或回复.
for(var i=0; i<images.length; i++) {
var t = document.createElement('IMG');
t.setAttribute('src',images[i]);
t.setAttribute('border', 0);
t.setAttribute('width',imageWidth);
t.setAttribute('height',imageHeight);
t.style.position = 'absolute';
t.style.visibility = 'hidden';
el.appendChild(t);
}
Run Code Online (Sandbox Code Playgroud)
试试这个:
for(var i=0; i<images.length; i++)
{
var t = document.createElement('IMG');
var link = document.createElement('a'); // create the link
link.setAttribute('href', 'www.example.com'); // set link path
// link.href = "www.example.com"; //can be done this way too
t.setAttribute('src',images[i]);
t.setAttribute('border', 0);
t.setAttribute('width',imageWidth);
t.setAttribute('height',imageHeight);
t.style.position = 'absolute';
t.style.visibility = 'hidden';
link.appendChild(t); // append to link
el.appendChild(link);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13132 次 |
| 最近记录: |