当所有文本框在jquery中都有值时,如何启用按钮?

nic*_*nic 4 javascript jquery jquery-ui javascript-events

我是编程新手.我已经给出了我的问题的描述,我有一对两个文本框.一个文本框用于url,另一个用于指令,但所有文本框都是根据数据库的值动态创建的.

例如$ testing_type_id = 2所以我得到两对文本框,让它称为bundle.$ i用于唯一地识别文本框.

  <input type = "text"  size="33"   class="uploadtxt1 url" name="txturl_<?php echo $testing_type_id ; ?>" id = "txturl_<?php echo $testing_type_id; ?>_<?php echo $i ; ?>" value="" />
             <input type = "text"  class="uploadtxt2" size="33" name="txtinstruction_<?php echo $testing_type_id ; ?>" id = "txtinstruction_<?php echo $testing_type_id; ?>_<?php echo $i ; ?>" value=""  /> <br/>
             <input type="submit" name="checkout" id="checkout"   class="graybtn1 ptr  button_float_left_checkout" disabled="disabled" value="Proceed To Checkout" />
Run Code Online (Sandbox Code Playgroud)

这里我想做的就是如果所有bundle都有价值,无论是在一个文本框还是两个文本框中都这样启用提交按钮.如果我删除了值,那么使用jquery禁用提交按钮.

急需帮助.谢谢.

The*_*pha 6

我认为这会奏效

$(document).ready(function(){
    $("input[class^='uploadtxt']").keyup(function(e){
        var alltxt=$("input[class^='uploadtxt']").length;
        var empty=true;
        $("input[class^='uploadtxt']").each(function(i){
            if($(this).val()=='')
            {
                empty=true;
                $('#checkout').prop('disabled', true);
                return false;
            }
            else
            {
                empty=false;
            }
        });
        if(!empty)  $('#checkout').prop('disabled', false);                    
    });
});?
Run Code Online (Sandbox Code Playgroud)

一个例子是在这里.