1

我无法显示来自文件 URL 的照片。[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';
    }
4

2 回答 2

3

尝试

userDiv.innerHTML=htmlStr;
userDiv.appendChild(imageHold);

htmlStr应该有有效的标记。

于 2013-01-17T12:26:14.437 回答
0

You can't simply use:

userDiv.innerHTML=htmlStr+imageHold;

Instead use:

 userDiv.innerHTML=htmlStr+'<img src="'+imageHold.src+'" />";
于 2013-01-17T12:28:28.653 回答