1. 程式人生 > >拿到input file上傳文件名字 顯示到頁面中

拿到input file上傳文件名字 顯示到頁面中

spl file html div his clas javascrip brush .html

$(".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> 

拿到input file上傳文件名字 顯示到頁面中