disable submit button until file selected for upload

后端 未结 5 787
名媛妹妹
名媛妹妹 2020-12-08 10:30

I have a form for uploading images. I\'d like to disable the submit button, until user selects an image to upload. I\'d like to do it with jQuery. Currently I have a JavaScr

5条回答
  •  时光说笑
    2020-12-08 11:25

    The following seems to work reliably in Chrome and Firefox (Ubuntu 10.10), I'm unable to check on other platforms at the moment:

    jQuery

    $(document).ready(
        function(){
            $('input:file').change(
                function(){
                    if ($(this).val()) {
                        $('input:submit').attr('disabled',false);
                        // or, as has been pointed out elsewhere:
                        // $('input:submit').removeAttr('disabled'); 
                    } 
                }
                );
        });
    

    html

    Demo at JS Fiddle.

提交回复
热议问题