disable submit button until file selected for upload

后端 未结 5 808
名媛妹妹
名媛妹妹 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:29

    If you're a fan of ternary expressions:

    $(document).ready(function(){
        var $submit = $('#submit_document');
        var $file = $('#file_path');
    
        $file.change(
            function(){
                $submit.attr('disabled',($(this).val() ? false : true));
            }
        );
    });  
    

提交回复
热议问题