Examples of js Image Upload and preview functions, and examples of js Image Upload

Source: Internet
Author: User

Examples of js Image Upload and preview functions, and examples of js Image Upload

This document describes how to upload images and preview images in JavaScript. Share it with you for your reference. The specific analysis is as follows:

According to some people's code on the internet, I wrote a function to upload images for timely preview.

 <input type = "file"/> function DisplayImage (fileTag, imgTagId) {var allowExtention = ".jpg.png.gif"; var extentionArr = fileTag. value. split ('. '); var extention = extentionArr [extentionArr. length-1]; if (! (AllowExtention. indexOf (extention)>-1) {alert ("Please upload image! ");} Else {// for adveced broswer (the newest ie, chrome, ff) if (typeof (FileReader )! = "Undefined") {var reader = new FileReader (); reader. readAsDataURL (fileTag. files [0]); reader. onload = function (e) {document. getElementById (imgTagId ). setAttribute ("src", e.tar get. result) ;}} else {// for (ie6) document. getElementById (imgTagId ). setAttribute ("src", fileTag. value );}}}

I hope this article will help you design javascript programs.

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.