![](/img/trans.png)
[英]How to get width and height of an image while using jquery resizable() function?
[英]How to get width and height of image from this function?
我如何才能在下面的代码之外获取w
和h
值。 我需要获取选择上传的每个图像的宽度和高度。
var widt;
var hit;
reader.readAsDataURL(file);
reader.onload = function (_file) {
image.src = _file.target.result; // url.createObjectURL(file);
image.onload = function () {
var w = this.width,
h = this.height,
t = file.type, // ext only: // file.type.split('/')[1],
n = file.name
widt = w;
hit = h;
};
};
console.log(widt);
在这里console.log
返回undefined
。
您的变量名是widt
并且您正在控制台日志中使用width
。 尝试:
console.log(widt);
另外,将该控制台日志放入image.onload
函数以获取正确的响应。
您在以下代码行的末尾错过了分号
n = file.name
码:
image.onload = function () {
var w = this.width,
h = this.height,
t = file.type,
n = file.name;
widt = w;
hit = h;
console.log(widt);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.