我是编程新手。在这里我描述了我的问题 我有一对两个文本框。一个文本框用于 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" />
这里我想做的是,如果所有 bundle 都具有值(value),无论是在一个文本框中还是在两个文本框中都启用提交按钮。如果我删除了值,那么使用 jQuery 禁用提交按钮。
最佳答案
我觉得这行得通
$(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);
});
});
一个例子是 here .
关于javascript - 当所有文本框在 jQuery 中都有值时如何启用按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9946890/