如何用JS得到火狐浏览器中file的上传图片路径 火狐浏览器怎么用JS得到上传图片的完全路径注意:用document.getElementById("file").value;只能得到图片名 请各位高手指教~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个路径恐怕得不到. 但是可以得到这张图片的base64数据,从而可以实现图片的本地预览将以下代码放在firefox中运行<form name="form4" id="form4" method="post" action="#"> <input type="file" name="file4" id="file4" onchange="preview4()" /> <img id="pic4" src="http://avatar.profile.csdn.net/C/E/7/2_diandian82.jpg" alt="图片在此显示" width="120"/></form><script type="text/javascript">function preview4(){ var x = document.getElementById("file4"); var y = document.getElementById("pic4"); if(!x || !x.value || !y) return; var patn = /\.jpg$|\.jpeg$|\.gif$/i; if(patn.test(x.value)){ y.src=document.getElementById('file4').files.item(0).getAsDataURL(); } else{ alert("您选择的似乎不是图像文件。"); }}</script> <script language='javascript'> function getFullPath(obj) { if(obj) { //ie if (window.navigator.userAgent.indexOf("MSIE")>=1) { obj.select(); return document.selection.createRange().text; } //firefox else if(window.navigator.userAgent.indexOf("Firefox")>=1) { if(obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } </script> <body> <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" /> <img id="img" /> </body> js错误:例外被抛出且未被接住 javascript调用google地图 浏览器的关闭和刷新 怎么改变指定字符的样式? 取ifeam的值 ie 上可以运行,firefox不行 ??!! js调用dll的小问题 老大们帮看看 求“使用IE如何实现真正全屏的解决方案” fason(阿信)请进!500分求一个程序! 各位大侠帮帮忙——————我想实现在同一页的基础上生成一些表单组件 用javascript动态添加文本域,但post无法收到所添加的数值 js下拉菜单问题 jquery如何用正则提取class里面的数字?
<form name="form4" id="form4" method="post" action="#">
<input type="file" name="file4" id="file4" onchange="preview4()" /> <img id="pic4" src="http://avatar.profile.csdn.net/C/E/7/2_diandian82.jpg" alt="图片在此显示" width="120"/>
</form><script type="text/javascript">
function preview4()
{
var x = document.getElementById("file4");
var y = document.getElementById("pic4"); if(!x || !x.value || !y) return; var patn = /\.jpg$|\.jpeg$|\.gif$/i; if(patn.test(x.value)){
y.src=document.getElementById('file4').files.item(0).getAsDataURL();
}
else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script> <body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>