如何使用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>