Implementation of jquery based on the upload picture and picture size verification, picture preview effect code _jquery

Source: Internet
Author: User
jquery implementation upload picture and picture size verification, picture preview effect code
Upload Image Verification
Copy Code code as follows:

*/
function Submit_upload_picture () {
var file = $ (' File_c '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("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 ');
}
}

validation of picture types and sizes
Copy Code code as follows:

Example Two
function Validate_edit_logo (a) {
var file = $ (' file '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("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 pictures of size less than 100k ');
if (a==1) {
return false;
}
}
if (a==1) {
return true;
}
}
}

Picture Preview
Copy Code code as follows:

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 size of the uploaded file
var img = document.createelement ("img");
IMG.SRC = local;
var filesize = img.filesize;
Img.onload = function () {filesize=this.filesize;}
if (img.filesize>5242880) {
Alert ("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 = "";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.