This article mainly introduces how to upload an image. js judges the image size and format and is compatible with IE. If you need it, refer to the following JavaScript code:
$ (". Head"). change (function () {var val = $ (this). val (); if (! Val. match (/. jpg |. gif |. png |. bmp/I) {imgtype = false; alert ('invalid image format! ');} Else {if (FileReader) {var reader = new FileReader (), file = this. files [0]; reader. onload = function (e) {var image = new Image (); image. src = e.tar get. result; image. onload = function () {if (image. width & gt; 128 | image. height> 128) {fill = false; alert ("the Avatar size should be between X") ;}}; reader. readAsDataURL (file);} else {// This is ie9 version $ (". preview_size_fake "). show (); var objPreviewSizeFake = $ (". preview_size_fake "). get (0); var fileupload = $ (this ). get (0); fileupload. select (); fileupload. blur (); path = document. selection. createRange (). text; if (/"\ w \ W "/. test (path) {path = path. slice (1,-1);} objPreviewSizeFake. filters. item ('dximagetransform. microsoft. alphaImageLoader '). src = path; if (objPreviewSizeFake. offsetWidth> 128 | objPreviewSizeFake. offsetHeight> 128) {fill = false; alert ("the Avatar size should be between X");} document. selection. empty ();}}});
Css code (this must be written. If it is not written, it will not work in ie)
. Preview_size_fake {/* This object is only used to obtain the original size of the image under IE, and has no other purpose */filter: progid: DXImageTransform. microsoft. alphaImageLoader (sizingMethod = image); height: 1px; visibility: hidden; overflow: hidden; display: none ;}
Html code: