javascript用于验证图像的宽度和高度,以便在asp.net中使用fileupload控件进行上传 [英] javascript for validate width and height of image befor uploading using fileupload control in asp.net

查看:52
本文介绍了javascript用于验证图像的宽度和高度,以便在asp.net中使用fileupload控件进行上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

heyy ...



在使用fileupload控件上传之前,验证图像的宽度和高度是否有javascript或jquery .aspx ..



我通过互联网搜索..我得到了服务器端验证,但我没有得到javascript或jquery ....

解决方案

您可以使用html输入类型文件控件而不是asp.net图像控件并跟进jquery,这可能对您有所帮助,但请记住它可能不适用于所有浏览器,但在ff和chrome上它就像一个魅力。

< input type =   file name =   photo id =   photoInput /> 



  var  _URL =  window  .URL; 

#photoInput)。change( function (e){
var file,img;
if ((file = this .files [ 0 ])){
img = new Image();
img.onload = function (){
alert( 宽度: + .width + 高度: + .height); // 这将为您提供图像宽度和高度,您可以在此轻松验证....
};
img.src = _URL.createObjectURL(file);
}
});


heyy...

Is there is javascript or jquery for validate the width and height of image before uploading using fileupload control in .aspx..

I searched through internet ..I got server side validation but I didn't get javascript or jquery for this....

解决方案

you can use html input type file control instead of asp.net image control and follow up jquery which might help you but remember it might not work on all browsers but on ff and chrome it works like a charm.

<input type="file" name="photo" id="photoInput" />


var _URL = window.URL;


("#photoInput").change(function (e) { var file, img; if ((file = this.files[0])) { img = new Image(); img.onload = function () { alert("Width:" + this.width + " Height: " + this.height);//this will give you image width and height and you can easily validate here.... }; img.src = _URL.createObjectURL(file); } });


这篇关于javascript用于验证图像的宽度和高度,以便在asp.net中使用fileupload控件进行上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆