how to check if a file is selected using javascript?

后端 未结 3 1298
情深已故
情深已故 2021-01-18 05:11

In php this is how you would check if a file is selected:

$_FILES[\'item\'][\'size\']>0

what about in JavaScript?

I need to know

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 05:34

    I use this javascript:

    var file_selected = false;
    function showNoFile() {
        if(!file_selected) { alert('No file selected!'); } // or anything else
    }
    

    with this html for the file button:

    
    ....
    
    

    hope that helps!

提交回复
热议问题