我在显示文件网址中的照片时遇到问题。我只是在页面上获得[Object HTML IMAGE ELEMENT]
,即使我认为我将此元素指向图像源。
//database query results...
for(var i = 0; i < len; i++){
theID = results.rows.item(i).id;
console.log(theID);
theName = results.rows.item(i).username;
htmlStr += theName;
console.log(theName);
thePhoto = results.rows.item(i).imagepath;
console.log(thePhoto);
var imageHold= new Image();
imageHold.src = thePhoto;
console.log("this is the src:"+imageHold.src);//THIS IS GIVING ME THE PATH
var userDiv = document.createElement("div");//Create the div
userDiv.innerHTML=htmlStr+imageHold;//IS THE PROBLEM WHAT I AM DOING HERE?
document.getElementById('showUsers').appendChild(userDiv);//append it to the document
userDiv.style.display = 'block';
}
答案 0 :(得分:3)
尝试
userDiv.innerHTML=htmlStr;
userDiv.appendChild(imageHold);
htmlStr
应该有有效的标记。
答案 1 :(得分:0)
你不能简单地使用:
userDiv.innerHTML = htmlStr + imageHold;
改为使用:
userDiv.innerHTML=htmlStr+'<img src="'+imageHold.src+'" />";