现在的位置: 首页 > 综合 > 正文

JavaScript得到上传文件的文件名

2018年05月21日 ⁄ 综合 ⁄ 共 369字 ⁄ 字号 评论关闭
<input name="imgfile" type="file" id="imgfile" size="40" 
onchange="getFileName('t',this.form.imgfile);" />

<input type="text" id="t">

<script type="text\javascript">
function getFileName(controlID,fileBox) {
if (fileBox.value){
 var path = fileBox.value;
 var fileName = path.substring(path.lastIndexOf('\\')+1,path.lastIndexOf('.'));
 document.getElementById(controlID).value = fileName;
}
}
</script> 

抱歉!评论已关闭.