高分请教,jquery问题,如何得到input file 的路径

njxiaod 2010-07-19 02:28:46
<input type="file" size="22" id="upload" class="form-file" accept="png,gif,jpg,jpeg" name="bimg">

我写的代码只能得到文件名,不能得到上传时候的本地路径。比如 C:\Documents and Settings\Administrator\My Documents\Downloads\Breadcrumb_error.jpg



$('input[type=file]').change(function(){
$('#demo').html($(this).val()); //只能得到Breadcrumb_error.jpg 而我想得到全部路径 C:\.......
});


谢谢
...全文
2846 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
njxiaod 2010-07-19
  • 打赏
  • 举报
回复
没能解决问题,最后选择了另外的解决方案。谢谢各位热心。
kyzy_yy_pm 2010-07-19
  • 打赏
  • 举报
回复
ff下的方法被我给弄丢了,不过就算不丢这些也没什么用了,以下是ie里的
<script language="javascript">
function preview(fileObj, id){
fileObj.document.execCommand("SelectAll");
var filePath = document.selection.createRange().text;
alert(filePath);
}

</script>

<img id="img" style="display:none">
<input type="file" id="file" name="file" onchange="preview(this, 'img')">
hoojo 2010-07-19
  • 打赏
  • 举报
回复

var f = document.getElementById("upload");
alert(f.value);
jquery不能获得了
kyzy_yy_pm 2010-07-19
  • 打赏
  • 举报
回复
jquery目前貌似已经不能再获取到那样的路径了,浏览器更改了,想问下,你想干什么?
njxiaod 2010-07-19
  • 打赏
  • 举报
回复
ff下测试不行,ie没测试。
zoujp_xyz 2010-07-19
  • 打赏
  • 举报
回复
IE下

//判断浏览器类型
var isIE = (document.all) ? true : false;
var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);

var file=document.getElementById("fileupload1");
if(isIE7 || isIE8)
{
file.select();
var path=document.selection.createRange().text;
document.selection.empty();
}

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧