Jquery 输入图像文件widh&;高度
我想在更新之前得到输入文件图像的宽度和高度。最好马上进去换衣服。但我无法得到实际的宽度和高度 这是cshtml代码: 这里的“imgIdentityPicture”是图像视图框Jquery 输入图像文件widh&;高度,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我想在更新之前得到输入文件图像的宽度和高度。最好马上进去换衣服。但我无法得到实际的宽度和高度 这是cshtml代码: 这里的“imgIdentityPicture”是图像视图框 <div class="col-md-2 col-md-offset-1"> <input type="file" name="IdentityPicture" id="IdentityPicture" />
<div class="col-md-2 col-md-offset-1">
<input type="file" name="IdentityPicture" id="IdentityPicture" />
</div>
$.validator.addMethod('imagedim',函数(值、元素、参数){
var_URL=window.URL;
var-img;
if((元素=this.files[0])){
img=新图像();
img.onload=函数(){
console.log(“Width:+this.Width+”Height:+this.Height);//这将为您提供图像宽度和高度,您可以在此处轻松验证。。。。
返回this.width>=param
};
img.src=\u URL.createObjectURL(元素);
}
});
看这个。。()试试这个
$(function(){
$('#IdentityPicture').on('change', function (e) {
e.preventDefault();
var form = $(this).parents('form:first');
$('#imgIdentityPicture').attr("src", '/Content/Images/Animation/loading_fast.gif');
/* code to get width of image */
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
alert(this.width + " " + this.height);
};
}
form.ajaxSubmit({
success: function (data) {
$('#imgIdentityPicture').attr("src", data.Url);
$('#SettleBeneficiaryIdPicture').val(data.FileName);
},
beforeSubmit: function (arr, $form, options) {
},
error: function () {
alert('error');
}
});
});
});
<input type="file" name="photo" id="photoInput" />
$.validator.addMethod('imagedim', function(value, element, param) {
var _URL = window.URL;
var img;
if ((element = this.files[0])) {
img = new Image();
img.onload = function () {
console.log("Width:" + this.width + " Height: " + this.height);//this will give you image width and height and you can easily validate here....
return this.width >= param
};
img.src = _URL.createObjectURL(element);
}
});
$(function(){
$('#IdentityPicture').on('change', function (e) {
e.preventDefault();
var form = $(this).parents('form:first');
$('#imgIdentityPicture').attr("src", '/Content/Images/Animation/loading_fast.gif');
/* code to get width of image */
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
alert(this.width + " " + this.height);
};
}
form.ajaxSubmit({
success: function (data) {
$('#imgIdentityPicture').attr("src", data.Url);
$('#SettleBeneficiaryIdPicture').val(data.FileName);
},
beforeSubmit: function (arr, $form, options) {
},
error: function () {
alert('error');
}
});
});
});