【发布时间】:2016-10-12 15:48:11
【问题描述】:
我有通过 php 动态生成的复选框,如果所有具有相似类值的复选框都没有被选中,我想隐藏某个按钮,如果它们被选中,我想重新启用它:
生成复选框的php代码是
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Description</th>
<th>Status</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
foreach ($checks as $m => $check) {
$item ="";
$checkbox ="";
$textinput ="";
$displayx="";
if ($check->mandatory_customer == 1) { //mandatory customer checks
$displayx .="<i style='color:red;'>*</i>";
$item .= $check->item.$displayx;
$checkbox .='<input type="checkbox" class="1" id="'.$m.'"' ;
$textinput .='<input type="text" class="1" id="'.$m.'"' ;
} else { //not mandatory customer
$item .= $check->item;
$checkbox .='<input type="checkbox" class="0" id="'.$m.'"' ;
$textinput .='<input type="text" class="0" id="'.$m.'"' ;
}
echo "<tr id='" . $m . "'>";
echo "<td>" . $m . "</td>";
echo "<td>" . $item . "</td>";
echo "<td>".$checkbox."</td>";
echo "<td>".$textinput."</td>";
echo "</tr>";
}
?>
}
</tbody>
我还有一个按钮,如果没有选中所有 1 类复选框,我想禁用它,如果它们都使用 jquery 选中,则启用它
<button class="btn btn-success" id="approve_btn">Approve</button>
我试过了:
$('tbody tr').each(function () {
if ($(this).attr('class:1').find('.myCheckBox').prop('checked')) {
doEnableButton = true;
}
if (!doEnableButton) {
$('#approve_btn').prop('disabled', 'disabled')
}
else {
$('#approve_btn').removeAttr("disabled");
}
});
});
我检查了几个资源,但大多数都没有帮助 以上失败了我该怎么做
【问题讨论】:
标签: javascript php jquery checkbox