【发布时间】:2018-10-13 09:36:30
【问题描述】:
上传前我需要检查图片的尺寸。我在 javascript 中创建了一个用于验证的函数,如下所示
$('#destSubmit').click(function() {
var img = document.getElementById('destImage');
var width = img.naturalWidth ;
var height = img.naturalHeight ;
console.log('width : ' + width + '|| Height : ' + height);
if(height != 100 || width != 100){
alert(error);
}
}
但它显示宽度和高度为undefined;
我知道这是一个重复的问题,但经过长时间的研究后我找不到解决方案。 尝试了此处列出的解决方案How to get image size (height & width) using JavaScript?,但没有用。
【问题讨论】:
-
您搜索的链接有有效的答案。
-
什么是 naturalWidth ?,您之前添加了这些?
标签: javascript