2013-04-30 58 views
0

我創建了此功能,它將圖像添加到div,以後我將編碼以刪除所述div中的信息。我不斷收到這部分代碼中的DOM Exception 8錯誤。任何幫助,將不勝感激。DOM Excptn 8:將圖片添加到Div

addDelete:function(imagename,idname) { 
    var img = document.createElement("img"); 
    img.setAttribute("src", 'http://cpms.byu.edu/sites/all/themes/collage/src_submit/images/cross.png'); 
    img.setAttribute("id", imagename); 
    document.getElementById(idname).appendChild("img"); 
} 

回答

1
document.getElementById(idname).appendChild("img"); 
              ^^

您傳遞字符串"img",不是變量img了!

document.getElementById(idname).appendChild(img);