<%@ 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?