如何爲使用以下javascript創建的圖像添加鏈接。如何使用javascript添加鏈接到使用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);
}
它不在HTML文檔上使用'setAttribute'是個好主意。有很多情況下,這在IE中失敗(儘管不是你打的)。首選DOM Level 1 HTML屬性:'t.src = images [i];'等 – bobince 2010-04-12 11:04:07