拿到input file上传文件名字 显示到页面中

$(".aFileBtn").on("change","input[type='file']",function(){
    var filePath=$(this).val();
    //filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1
    if(filePath.length > 0){
        $(".fileerrorTip").html("").hide();
        var arr=filePath.split('\');
        var fileName=arr[arr.length-1];
        $(".showFileName").html(fileName);
    }else{
        $(".showFileName").html("");
        $(".fileerrorTip").html("您未上传文件,或者您上传文件类型有误!").show();
        return false
    }
})
<a class="selfConBtn aFileBtn">选择文件<input type="file"  /></a>
        <span class="fileerrorTip"></span>
         <span class="showFileName"></span>
 <a href="#"  class="selfConBtn">点击上传</a> 
原文地址:https://www.cnblogs.com/laugh/p/9842565.html