jquery在不同浏览器获取文件路径出现问题!
<input type="file" name="file" id="file1" src=""/>
<input type="button" id="btn" value="上传" />
然后jquery如下:
$(function(){
$("#btn").click(function(){
alert( $('#file1').val() );
})
})
想要获得上传文件的路径,用IE打开可以成功显示,但用chrome打开时显示C:\fakepath\文件名
只好改写代码,将不同浏览器分别判断:
$(function(){
$("#btn").click(function(){
if($.browser.msie){
alert("IE"+$.browser.version);
alert( $('#file1').val() );
}
if($.browser.webkit){
var filename = $('#file1').val().replace(/C:\\fakepath\\/i, '');
//或者var filename = $('#file1').val().split('\\').pop();
alert("chrome"+$.browser.version);
alert(filename);
}
})
})
在chrome下实现了将C:\fakepath\去掉 但只能显示出文件名 不能显示完整的绝对路径
搜了很多文章 还是没有好的解决办法 希望会的朋友能指点一下 谢啦!
jquery在不同浏览器获取文件路径出现问题!的更多相关文章
- C# 获取文件路径
1.C# 获取文件路径:http://www.cnblogs.com/bq-blog/archive/2012/09/01/2666394.html
- 使用Class.getResource和ClassLoader.getResource方法获取文件路径
自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...
- iOS: 获取文件路径
iOS: 获取文件路径 // 例如 - (NSString *)applicationDocumentsDirectory { return [NSSearchPathForDirectories ...
- [[NSBundle mainBundle] pathForResource:fileName ofType:]获取文件路径不成功
目标文件明明已经加入项目了,但是使用[[NSBundle mainBundle] pathForResource:fileName ofType:]来获取文件路径的时候却为nil: 遇到这个问题大家需 ...
- Java中获取文件路径
Java中获取文件路径 1.实例说明 (1)得到 ClassPath的绝对URI路径 Thread.currentThread().getContextClassLoader().getResourc ...
- Android中获取文件路径的方法总结及对照
最近在写文件存贮,Android中获取文件路径的方法比较多,所以自己也很混乱.找了好几篇博客,发现了以下的路径归纳,记录一下,以备不时之需 Environment.getDataDirectory() ...
- PHP常用获取文件路径的函数集合整理
转自: http://blog.sina.com.cn/s/blog_71ed1b870102vslg.html 我们在开发PHP项目过程中,经常会用到包含文件,所以有时候需要获取文件的相对路径或者绝 ...
- python获取文件路径, 文件名, 后缀名
def get_filePath_fileName_fileExt(fileUrl): """ 获取文件路径, 文件名, 后缀名 :param fileUrl: :ret ...
- 牛客网Java刷题知识点之File对象常用功能:获取文件名称、获取文件路径、获取文件大小、获取文件修改时间、创建与删除、判断、重命名、查看系统根目录、容量获取、获取某个目录下内容、过滤器
不多说,直接上干货! 获取文件名称.获取文件路径.获取文件大小.获取文件修改时间 FileMethodDemo.java package zhouls.bigdata.DataFeatureSelec ...
随机推荐
- poj Pie
http://poj.org/problem?id=3122 #include<cstdio> #include<cstring> #include<cmath> ...
- 属性动画(Property Animation)资源
Animator 代表一个属性动画,但它只是一个抽象类,通常会使用它的子类:AnimatorSet.ValueAnimator.ObjectAnimator.TimeAnimator. 定义属性动画的 ...
- POJ1088 滑雪(记忆化搜索)
题目链接. 分析: 状态转移方程 d[i][j] = max(d[i-1][j], d[i+1][j], d[i][j-1], d[i][j+1]). #include <iostream> ...
- Sublime 2 Installation for Linux
Linux You can download the package and uncompress it manually. Alternatively, you can use the comman ...
- 【转】Contrary to the answers here, you DON'T need to worry about encoding!
For those goals, I honestly do not understand why people keep telling you that you need the encoding ...
- 基于Struts2 的日志管理系统的Java实现
1.首先,项目的架构如下: 2.com.sxl.dba 中:OracleConnector.java package com.sxl.dba; import java.sql.*; ...
- 点击按钮弹出div,留用
<input type="button" onclick="document.getElementById('div').style.display=(docume ...
- 两个关于XML解析报错问题小记
Caused by: org.xml.sax.SAXParseException: The string "--" is not permitted within comments ...
- crtmpserver 基本流程分析
近期在研究crtmpserver,这里记录下学习过程,首先我们先分析下基本流程. 1.初始化流程 InitNetworking---初始化网络 Initialize Logger::Init()--- ...
- 完毕port(CompletionPort)具体解释 - 手把手教你玩转网络编程系列之三
手把手叫你玩转网络编程系列之三 完毕port(Completion Port)具体解释 ...