Button disable unless both input fields have value

前端 未结 4 1432
野性不改
野性不改 2021-01-06 16:31

I have a form with two input fields and a submit button on my page, I would like to have the feature that the \'submit\' button is disabled until there are

4条回答
  •  借酒劲吻你
    2021-01-06 17:34

    Here's a solution using jQuery:

    HTML (note that I added a id to the submit button):

    JavaScript/jQuery:

    $(':text').keyup(function() {
        if($('#first_name').val() != "" && $('#second_name').val() != "") {
           $('#submit').removeAttr('disabled');
        } else {
           $('#submit').attr('disabled', true);   
        }
    });
    

    Working example: http://jsfiddle.net/nc6NW/1/

提交回复
热议问题