嘿,我目前在上传表单中遇到图像验证的困难。
当点击“提交”按钮时,问题出现在我的验证/提交函数中。 我的计划是检查图像尺寸。我是这样做的:
var file = $('.html5-wrapper .mandatoryImg')[i].files[0]
$scope.image = [];
var fileReader = new FileReader();
var image = new Image();
fileReader.onload = function (event) {
image.src = event.target.result;
image.onloadend = function() {
$scope.image.push(this.width)
$scope.image.push(this.height)
// update scope after image is updated
$scope.$apply();
};
};
fileReader.readAsDataURL(file);
var img = $scope.image
console.log(img);
console.log(img[0];)
第一个日志提供所需的数组。但是当我尝试在第二个日志中访问单个值时,该值是未定义的!
有人可以帮忙吗?