jQuery disable/enable submit button

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

I have this HTML:



How can I do something li

21条回答
  •  时光取名叫无心
    2020-11-22 07:48

    The problem is that the change event fires only when focus is moved away from the input (e.g. someone clicks off the input or tabs out of it). Try using keyup instead:

    $(document).ready(function() {
         $(':input[type="submit"]').prop('disabled', true);
         $('input[type="text"]').keyup(function() {
            if($(this).val() != '') {
               $(':input[type="submit"]').prop('disabled', false);
            }
         });
     });
    

提交回复
热议问题