对于Firefox。由于安全原因,它的路径被截断了。但是,他们提供了其他方法:
var img = document.createElement("IMG");if(document.all) img.src = document.getElementById('submit').value;else // Your solution for Firefox. img.src = document.getElementById('submit').files.item(0).getAsDataURL();document.getElementById('div').appendChild(img);
以下内容适用于Internet Explorer 7和Firefox 3。
<style type="text/css"> #prevImage { border: 8px solid #ccc; width: 300px; height: 200px; }</style><script type="text/javascript"> function setImage(file) { if(document.all) document.getElementById('prevImage').src = file.value; else document.getElementById('prevImage').src = file.files.item(0).getAsDataURL(); if(document.getElementById('prevImage').src.length > 0) document.getElementById('prevImage').style.display = 'block'; }</script><pre> IE8 needs a security settings change: internet settings, security, custom level : [] Include local directory path when uploading files to a server ( ) Disable (o) Enable </pre><form> <input type="file" name="myImage" onchange="setImage(this);" /></form><img id="prevImage" />
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)