Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从图像uri显示图像_Javascript_Imageurl - Fatal编程技术网

Javascript 从图像uri显示图像

Javascript 从图像uri显示图像,javascript,imageurl,Javascript,Imageurl,我无法显示文件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).usern

我无法显示文件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';
    }
//数据库查询结果。。。
对于(变量i=0;i
试试看

htmlStr
应该有有效的标记。

您不能简单地使用:

userDiv.innerHTML=htmlStr+imageHold

而是使用:

 userDiv.innerHTML=htmlStr+'<img src="'+imageHold.src+'" />";
userDiv.innerHTML=htmlStr+';

谢谢Marcell,我正在学习,所以有时我可以理解我需要做什么,但如果你明白我的意思,我不知道如何标记它。例如,这是可行的,但现在我不知道如何为它指定大小和宽度属性。是否有明确的标记约定资源?你的意思是为图像指定属性?只需使用
imageHold.style.[…]
更改内联样式属性。嗨,Sumit,我理解并请您参考我上面的评论。这不起作用,而且有一个语法错误-我认为结束引号应该是单引号。谢谢。
 userDiv.innerHTML=htmlStr+'<img src="'+imageHold.src+'" />";