jquery implements upload image and image size verification, picture preview effect code
jquery implements upload image and image size verification, picture preview effect code
Upload Image Verification
*/
function Submit_upload_picture () {
var file = $ (' File_c '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("The picture type must be one of the. Gif,jpeg,jpg,png")
}else{
$ (' Both_form '). action= "File!upload.action";
$ (' Both_form '). Submit ();
$ (' insert_img '). sethtml (' ");
$ (' Display_div '). SetStyle (' Display ', ' block ');
$ (' Upload_div '). SetStyle (' Display ', ' none ');
}
}
Verification of image type and size
Example Two
function Validate_edit_logo (a) {
var file = $ (' file '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("The picture type must be one of the. Gif,jpeg,jpg,png")
if (a==1) {
return false;
}
}else{
var image = new Image ();
image.src = file;
var height = image.height;
var width = image.width;
var filesize = image.filesize;
$ (' BeforeEnd '). Src=file;
$ (' div_regi_right '). SetStyle (' Display ', ' block ');
if (width>80 && height>80 && filesize>102400) {
Alert (' Please upload 80*80 pixels or images less than 100k in size ');
if (a==1) {
return false;
}
}
if (a==1) {
return true;
}
}
}
Picture preview
Example Three
function Viewimg (index) {
var name = ' uploadimg ' + index;
var Imgup = $ (name);
var Imgpath = GetPath (Imgup);
var local = Imgup.value;
var point = Local.lastindexof (".");
Determine the upload file size
var img = document.createelement ("img");
IMG.SRC = local;
var filesize = img.filesize;
Img.onload = function () {filesize=this.filesize;}
if (img.filesize>5242880) {
Alert ("The picture file is too big!") ");
return false;
}
Determine if it is a picture format
var imgname = imgup.value.substring (Imgup.value.lastindexof ("."), imgup.value.length);
Imgname = Imgname.tolowercase ();
if (imgname = ". jpg") && (imgname! = ". gif") && (imgname! = ". jpeg") && (imgname! = ". png") & & (imgname!= ". bmp")) {
Alert ("u8bf7u9009u62e9u56feu7247u6587u4ef6uff0cu8c22u8c22!");
Imgup.focus ();
Empty the value inside the file www.3ppt.com
Imgup.select ();
Document.selection.clear ();
} else {
Show pictures
document.getElementById ("Sig_preview" +index). innerHTML = " ';
}
if (index >=3) {
var cnt = index + 1;
$ ("img" + cnt). Style.display = "";
}
}
jquery implements upload image and image size verification, picture preview effect code