JQUERY:[1] Implement picture upload and preview

Source: Internet
Author: User

JQUERY:[1] Implement picture upload and preview the idea of the principle

1. Gets the URL of the image object to upload when input of the uploaded object is triggered and the local image is selected;

2. Assign the object URL to the SRC attribute of the implementation-written IMG tag

File Object

  The file object can be used to obtain information about the files and can also be used to read the contents of the file, typically, the file object is a FileList object returned from the user selecting a file on an INPUT element. It can also be from a DataTransfer object generated by a drag-and-drop operation.

Blob Object

  a Blob object is a class file object that contains the raw data that is read-only, and the data in the Blob object does not necessarily have to be native form in JavaScript . The file interface base blob, which inherits the functionality of the BLOB and extends the support for local files on the user's computer, the object URL that we want to get is actually obtained from the Blob object.

Instance Code
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4     <MetaCharSet= "UTF-8">5     <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0">6     <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge">7     <Scriptsrc= "Jquery-2.1.4.js"></Script>8     <title>Document</title>9 </Head>Ten <Body> One     <inputID= "Upload"type= "File"> A     <imgID= "Preview"src=""> -     <Script> -         $('#upload'). Change (function(){ the             varobj=document.getElementById ('Upload'). files[0]; -             varASRC=window. Url.createobjecturl (obj); - document.getElementById ("Preview"). SRC=asrc; -         }) +     </Script> - </Body> + </HTML>
Effect

JQUERY:[1] Implement picture upload and preview

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.