How to check input file is empty, and also display an alert if png format is selected using jquery

后端 未结 4 1419
谎友^
谎友^ 2021-02-07 11:23

I have got an input file upload , need to check which file is uploaded / if no file is selected by the client using jquery.



        
4条回答
  •  遇见更好的自我
    2021-02-07 11:41

    See the sample I have created:

    http://jsfiddle.net/G7xke/


    And JavaScript:

    $("#check").click(function(){
        var fileName = $("#file1").val();
        if(fileName.lastIndexOf("png")===fileName.length-3)
            alert("OK");
        else
            alert("Not PNG");
    })
    

提交回复
热议问题