首页 > Web开发 > 详细

JS如何获取上传标签的文件路径和文件名?

时间:2015-12-18 14:30:53      阅读:106      评论:0      收藏:0      [点我收藏+]

如何使用JS获取type="file"的标签上传文件的文件路径及文件名:

代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<input type="file" name="test" onchange="popFileName()" id="file">
<script type="text/javascript">

function getFileName(path){
var pos1 = path.lastIndexOf(‘/‘);
var pos2 = path.lastIndexOf(‘\\‘);
var pos = Math.max(pos1, pos2)
if( pos<0 )
return path;
else
return path.substring(pos+1);
}

function popFileName()
{
var path = document.getElementById("file").value;
alert(path+";---;"+getFileName(path));
}

</script>
</body>

JS如何获取上传标签的文件路径和文件名?

原文:http://www.cnblogs.com/wangqiideal/p/5056918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!