JavaScript+JSON问题:无法加载照片/undefined.jpg
JavaScript + JSON issue: not able to load photos/undefined.jpg
我在这个JavaScript代码中连接图像名称时遇到问题。它来自JSON,这让我作为一个初学者变得更加困难。如果有任何帮助,我将不胜感激!这是我的JS:
function log(msg){
console.log(msg)
}
function createImage(file, parent){
var str = file;
var filename = ("photos/"+filename+".jpg");
var image = new Image();
image.src = filename;
image.style.width = "50px";
image.style.height = "auto";
image.onload = function(){
log('good ' + file );
parent.appendChild(image); //adds the image to the page!
}
image.onerror = function(){
log('not able to load ' + filename );
//parent.appendChild(image);
}
}
var文件名和文件混淆。)
function log(msg){
console.log(msg)
}
function createImage(file, parent){
var str = file; // unused
var filename = ("photos/"+file+".jpg"); // filename was undefined here.
var image = new Image();
image.src = file;
image.style.width = "50px";
image.style.height = "auto";
image.onload = function(){
log('good ' + file );
parent.appendChild(image); //adds the image to the page!
}
image.onerror = function(){
log('not able to load ' + filename );
//parent.appendChild(image);
}
}
相关文章:
- 漂亮照片图片库中的Facebook赞按钮
- 图片照片库
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- /undefined在我的404错误日志中多次出现
- RequireJS向模块传递配置总是返回undefined
- JSON数组数据返回Undefined
- 为什么会出现错误,“UncaughtTypeError:undefined不是函数”
- Array.lenght = undefined
- mongoose.connect undefined不是一个函数
- JavaScript”;.方法“;返回undefined
- Uncaught TypeError:undefined不是函数-ember js
- Jquery - table.row(tr) is undefined
- jQuery可以't获取data-*属性值,返回undefined
- noty.js is returning undefined
- 将照片从javascript发送到php
- 将对象的列表c#传递给javascript:undefined变量时出错
- $routeParams is undefined
- 试图打印/调用/或提醒数组中的对象:Getting Undefined
- jQuery Mobile Undefined不是一个函数
- JavaScript+JSON问题:无法加载照片/undefined.jpg