How to simply get the input file selected image, and in a div in the IMG to assign a value SRC implementation preview?

Source: Internet
Author: User

<%@ Page language="C #"autoeventwireup="true"codefile="Default2.aspx.cs"inherits="DEFAULT2"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title> <script src="Dist/jquery1.11.1.js"></script>"Form1"runat="Server"> <div> <input id="File_upload"Type="file"/><divclass="Image_container">"Preview"Width=" -"height=" -"></div> </div> </form></body>$ (function () {$ ("#file_upload"). Change (function () {var$file = $ ( This); varFileobj = $file [0]; varWindowurl = window. URL | |Window.webkiturl; varDataurl; var$img = $ ("#preview"); if(Fileobj && fileobj.files && fileobj.files[0]) {Dataurl= Windowurl.createobjecturl (fileobj.files[0]); $img. attr ('src', Dataurl); } Else{Dataurl=$file. Val (); varImgobj = document.getElementById ("Preview"); //two pits://1, when the Filter property is set, the element must already exist in the DOM tree, the dynamically created node, also need to be added to the DOM before setting the property, first set the attribute is added, invalid;//2, the SRC attribute needs to be added as follows, the above two ways to add, invalid;ImgObj.style.filter ="Progid:DXImageTransform.Microsoft.AlphaImageLoader (Sizingmethod=scale)"; ImgObj.filters.item ("DXImageTransform.Microsoft.AlphaImageLoader"). src =Dataurl;    }        }); });</script>

How to simply get the input file selected image, and in a div in the IMG to assign a value SRC implementation 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.