无法加载< img>到< div> [英] cannot load <img> to <div>
问题描述
这是我现在得到的结果
函数init(){
var elem = document.createElement(img);
elem.scr ='upload / creative-design-modern-furniture.jpg';
elem.setAttribute(height,768);
elem.setAttribute(width,1024);
elem.setAttribute(alt,furniture);
document.getElementById(imagegal)。appendChild(elem);
}
< body onload ='init();'>
< div id =imagegal>< / div>
现在,我知道这很容易,但是我没有在控制台中得到任何错误。
我在里面看到一个带有家具字样的白色方块(alt文本)。
包含所有图像的文件夹upload位于包含脚本文件的文件(apache / htdocs / myproject / upload)中
用户使用网站界面上传图片。在上传文件中,图像的所有大拇指都有一个金色的挂锁。那是什么?什么象征?我不知道
任何帮助/提示?
预先致谢
编辑
是的,这是一个错字。多谢你们。我想我应该得票倒票
但是,无论如何,每个缩略图旁边都有金色挂锁?
再次感谢
您的代码中存在拼写错误:
elem.src = '上传/创意设计现代-furniture.jpg';
// ^ ----在您的代码中是'scr'
I'm implementing as simple image gallery.
This is what I got for now
function init(){
var elem = document.createElement("img");
elem.scr='upload/creative-design-modern-furniture.jpg';
elem.setAttribute("height", "768");
elem.setAttribute("width", "1024");
elem.setAttribute("alt", "furniture");
document.getElementById("imagegal").appendChild(elem);
}
<body onload='init();'>
<div id="imagegal" ></div>
Now, I know this is easy, but I dont get any errors in the console. I see a white square with the word "furniture" inside (the alt text). I dont see the image.
The folder "upload" that contains all the images is inside the file that contains the script files (apache/htdocs/myproject/upload)
The images get uploaded by the user using website's interface. In the "upload" file, all the thumbs of the images have a little golden padlock on the side. What is that? What symbolizes? I dont know
Any help/tips?
Thanks in advance
EDIT
Yes , it was a typo. Thanks guys. I guess I deserve the down votes
But, anyway, whats with the golden padlock on the side of every thumbnail?
Thanks again
you have a typo in your code:
elem.src='upload/creative-design-modern-furniture.jpg';
// ^---- was 'scr' in your code
这篇关于无法加载< img>到< div>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!