<!DOCTYPE HTML> <HTML> <Head> <MetaCharSet= "UTF-8"> <title>3</title> <Script> functionGetFullPath (obj) {if(obj) {//Internet Explorer if(Window.navigator.userAgent.indexOf ("MSIE") >= 1) {obj.select (); returnDocument.selection.createRange (). text; } //Firefox if(Window.navigator.userAgent.indexOf ("Firefox") >= 1) { if(obj.files) {returnObj.files.item (0). Getasdataurl (); } returnObj.value; } //compatible with Chrome, Firefox, HTML5 get the path if (typeofFileReader!= "undefined") { varReader= NewFileReader (); Reader.onload= function(e) {document.getElementById ("pic"). SRC=E.target.result+ ""; } reader.readasdataurl (obj.files[0]); } Else if(Browserversion.indexof ("SAFARI") > -1) {alert ("Safari Browser is not supported for the time being!"); } } } functionshowpic (obj) {varFullPath=GetFullPath (obj); if(FullPath) {document.getElementById ("pic"). SRC=FullPath+ ""; } } </Script> </Head> <Body> <inputtype= "File"onchange= "Showpic (this)"> <imgsrc=""ID= "Pic"> </Body> </HTML>
Because of the job needs, I wrote a small demo, through their own assembly, you can achieve a certain demand.
A small demo that uploads images and previews images