jQuery disable/enable submit button

后端 未结 21 3303
难免孤独
难免孤独 2020-11-22 07:30

I have this HTML:



How can I do something li

21条回答
  •  孤城傲影
    2020-11-22 08:06

    eric, your code did not seem to work for me when the user enters text then deletes all the text. i created another version if anyone experienced the same problem. here ya go folks:

    $('input[type="submit"]').attr('disabled','disabled');
    $('input[type="text"]').keyup(function(){
        if($('input[type="text"]').val() == ""){
            $('input[type="submit"]').attr('disabled','disabled');
        }
        else{
            $('input[type="submit"]').removeAttr('disabled');
        }
    })
    

提交回复
热议问题