how to check if input field is empty

前端 未结 7 1041
别那么骄傲
别那么骄傲 2020-12-30 01:36

I\'m making a form with inputs, if the input type is empty then the button submit is disabled but, if the input fields is with length > 0 the submit button is enabled

<
7条回答
  •  梦谈多话
    2020-12-30 02:12

    This snippet will handle more than two checkboxes in case you decide to expand the form.

    $("input[type=text]").keyup(function(){
        var count = 0, attr = "disabled", $sub = $("#submit"), $inputs = $("input[type=text]");  
        $inputs.each(function(){
            count += ($.trim($(this).val())) ? 1:0;
        });
        (count >= $inputs.length ) ? $sub.removeAttr(attr):$sub.attr(attr,attr);       
    });
    

    Working Example: http://jsfiddle.net/sr4gq/

提交回复
热议问题