JS google兼容 获取input type="file"的值时不兼容其他浏览器 有什么好的办法
<HTML><HEAD><TITLE>上传图片预览功能</TITLE><metacontent="text/html;charset=utf-8"http-equiv="...
<HTML>
<HEAD>
<TITLE>上传图片预览功能</TITLE>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</HEAD>
<BODY>
<img src="1059_thumb_G_1341352293635.jpg" name="img1" id="img1" onload='if (this.width>140 || this.height>226) if (this.width/this.height>140/226) this.width=250; else this.height=200;'>
<br>
<input name="file" type="file" id=inp onChange="img1.src=this.value;">
</BODY>
</HTML>
google 的this.value 会为C:\fakepath\XX.jpg, 其他的浏览器为xx.jpg 展开
<HEAD>
<TITLE>上传图片预览功能</TITLE>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</HEAD>
<BODY>
<img src="1059_thumb_G_1341352293635.jpg" name="img1" id="img1" onload='if (this.width>140 || this.height>226) if (this.width/this.height>140/226) this.width=250; else this.height=200;'>
<br>
<input name="file" type="file" id=inp onChange="img1.src=this.value;">
</BODY>
</HTML>
google 的this.value 会为C:\fakepath\XX.jpg, 其他的浏览器为xx.jpg 展开
1个回答
展开全部
<HTML>
<HEAD>
<TITLE>上传图片预览功能</TITLE>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</HEAD>
<BODY>
<script language="javascript" >
function changeImg(){
val = document.getElementById('inp').value;
val = val.split("\\");
le = val.length - 1;
val = val[le]
document.getElementById('img1').src = val;
}
</script>
<img src="1059_thumb_G_1341352293635.jpg" name="img1" id="img1" onload='if (this.width>140 || this.height>226) if (this.width/this.height>140/226) this.width=250; else this.height=200;'>
<br>
<input name="file" type="file" id='inp' onChange="changeImg();">
</BODY>
</HTML>
只能将获取到的路径通过JS过滤掉,其他的也没有更好的办法
<HEAD>
<TITLE>上传图片预览功能</TITLE>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</HEAD>
<BODY>
<script language="javascript" >
function changeImg(){
val = document.getElementById('inp').value;
val = val.split("\\");
le = val.length - 1;
val = val[le]
document.getElementById('img1').src = val;
}
</script>
<img src="1059_thumb_G_1341352293635.jpg" name="img1" id="img1" onload='if (this.width>140 || this.height>226) if (this.width/this.height>140/226) this.width=250; else this.height=200;'>
<br>
<input name="file" type="file" id='inp' onChange="changeImg();">
</BODY>
</HTML>
只能将获取到的路径通过JS过滤掉,其他的也没有更好的办法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询