js图片预览兼容火狐和谷歌浏览器 1. [代码] [JavaScript]代码 /* 案例展示图片预览 */$(function(){ $("#file0").bind("change",function(){ clickupLoad(); });});function clickupLoad(){ var imgObject = document.getElementBy
1. [代码][JavaScript]代码
/* 案例展示图片预览 */ $(function(){ $("#file0").bind("change",function(){ clickupLoad(); }); }); function clickupLoad(){ var imgObject = document.getElementById('file0'); var getImageSrc = getFullPath(imgObject); // 本地路径 var srcs = window.URL.createObjectURL(imgObject.files[0]); var pos = getImageSrc.lastIndexOf("."); var lastname = getImageSrc.substring(pos, getImageSrc.length) // 图片后缀] if(srcs!=""){ $("#yulan2").attr("src",srcs); }else{ alert("请选择一张图片"); } } function getFullPath(obj) { //得到图片的完整路径 if (obj) { if (window.navigator.userAgent.indexOf("MSIE") >= 1){ obj.select(); return document.selection.createRange().text; }else if(window.navigator.userAgent.indexOf("Firefox") >= 1) { if (obj.files) { return window.URL.createObjectURL(obj.files[0]); } return obj.value; } return obj.value; } }