Javascript 使用带有“拆分”的jQuery警告输入“文件”文件名
我试图通过上传输入提醒文件名 这是我的 这是可行的,但是有一条C:Fakepath。。。差不多吧。 我只想要文件名,没有假路径。我试过使用split函数,但我不知道为什么它不起作用 html示例:Javascript 使用带有“拆分”的jQuery警告输入“文件”文件名,javascript,jquery,Javascript,Jquery,我试图通过上传输入提醒文件名 这是我的 这是可行的,但是有一条C:Fakepath。。。差不多吧。 我只想要文件名,没有假路径。我试过使用split函数,但我不知道为什么它不起作用 html示例: <html> <head> <title>Test Page</title> <script src="http://code.jquery.com/jquery-latest.js"></scr
<html>
<head>
<title>Test Page</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type="file" id="tester" />
</body>
</html>
有什么想法吗
谢谢大家! 您可以跳过斜杠:
bogus = triple.split("\\");
更新的提琴:您只需转义斜杠即可:
bogus = triple.split("\\");
更新的fiddle:如果您的web浏览器当前支持,这是任何不支持IE的web浏览器,您可以从输入的文件列表对象获取文件名
$(function() {
$('#tester').change(function() {
var files = this.files;
if (files && files.length) {
alert(files[0].name); //use the file api
}
else {
alert($(this).val().replace("C:\\fakepath\\", "")); //this is for IE
}
});
});
例如:
文档:如果您的web浏览器当前支持,这是任何非IE的web浏览器,您可以从输入的文件列表对象获取文件名
$(function() {
$('#tester').change(function() {
var files = this.files;
if (files && files.length) {
alert(files[0].name); //use the file api
}
else {
alert($(this).val().replace("C:\\fakepath\\", "")); //this is for IE
}
});
});
例如:
文档:完美。太简单了!非常感谢。11分钟前不能给你答案。太简单了!非常感谢。直到11分钟才能给你答案检查你能不能只要$'tester'.val.replaceC:\\fakepath\\,?你能不能只要$'tester'.val.replaceC:\\fakepath\\?