开发者

How do I use JQuery to detect if a file input has a file selected? [closed]

开发者 https://www.devze.com 2023-01-29 02:26 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post.
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

开发者_开发技巧 Improve this question

And then alert the file name?


This should suffice:

alert($('#your_input_box').val());

A file selection box is just an input box, from what I can tell. Read more from this question: jQuery: get the file name selected from <input type="file" />.


To detect if a file was selected, you can find out the length of the file input

$("#bCheck").click(function() { // bCheck is a input type button
    var fileName = $("#file1").val();

    if(fileName) { // returns true if the string is not empty
        alert(fileName + " was selected");
    } else { // no file was selected
        alert("no file selected");
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消