java web 开发 遇到的js问题
IE8上传文件时javascript取文件的真实路径的问题("C:\fakepath\xxxxx )
<title>My JSP 'fileupload.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function click1(){
var file = document.getElementById('file');
alert(getPath(file));
}
function getPath(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 obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
文件
<input type="file" id="file" name="file" />
<input type="button" onClick="click1();" value="submit">
</body>
</html>
很简单的一个js代码 放在本地访问修改后缀名为html js可以运行 没问题的
可是我放在我服务器中访问不运行 点击按钮没反应 不管是html还是jsp都没反应映
于是我alert(document.getElementById('file').value)可以得到对象
但是alert(document.getElementById('file').select())是未定义
在网上查了查说document.getElementById('file')没有select()属性 可是为什么本地可以不报错呢
求解 很郁闷
更多0