How to write the code for JS+HTML5 to realize the online preview function of pictures?
This article mainly explains the "JS+HTML5 to achieve picture online preview function code how to write", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "JS+HTML5 to achieve picture online preview function code how to write" it!
The specific code is as follows
HTML5 picture preview .hide {display:none;} Please select a picture of JPG/GIF
("# file0") .change (function () {var objUrl = getObjectURL (this.files [0]); console.log ("objUrl =" + objUrl); if (objUrl) {$("# img0"). Attr ("src", objUrl); $("# img0"). RemoveClass ("hide");}}); function getObjectURL (file) {var url = null If (window.createObjectURLFUND undefined) {/ / basic url = window.createObjectURL (file);} else if (window.URLQULFING undefined) {/ / mozilla (firefox) url = window.URL.createObjectURL (file);} else if (window.webkitURLFUBG undefined) {/ / webkit or chrome url = window.webkitURL.createObjectURL (file);} return url } Thank you for your reading, the above is the content of "how to write the code for JS+HTML5 to achieve picture online preview function". After the study of this article, I believe you have a deeper understanding of how to write the code for JS+HTML5 to achieve picture online preview function, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!