拿到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> 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM