HTML Select picture after preview, save and upload

Source: Internet
Author: User

HTML code:
<inputtype= "File"ID= "File"style= "Display:none;"><imgsrc=""width= "200px"Height= "200px"ID= "Img-change"><ButtonID= "BTN">Save picture</Button>
JS Code:
Implement click on the picture simultaneously, trigger type=file this input
$ ("#img-change"). Click (function  () {    $ ("#file"). Click ();})
When input changes, if there is a picture, then preview the picture (here only to determine the changes in the file, not judging the picture)
$ ("#file"). Change (function(event) {varFiles =event.target.files, file; if(Files && files.length > 0) {        //get the currently uploaded fileFile = Files[0];//Action of file size check        if(File.size > 1024 * 1024 * 2) {alert (' Picture size cannot exceed 2mb! '); return false; }        //Gets the URL tool for window        varURL = window. URL | |Window.webkiturl; //generating a destination URL from file        varImgurl =url.createobjecturl (file); //Use attr to change the SRC attribute of img to the obtained URL$ ("#img-change"). attr ("src"), Imgurl);        //Use the following sentence to release a servo to this URL in memory, the URL will be invalid after the run        //Url.revokeobjecturl (imgurl);    }})

HTML Select picture after preview, save and upload

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.