我正在使用在while循环中显示的复选框。但我想禁用我的删除按钮之前,任何复选框被选中。我面临的困难,因为我已经将复选框名称存储为数组。怎么做呢?我的代码是
<form action="delete_mock.php" method="POST">
<table border="1" style ="width:100%">
<caption>Mock Test Details of <span style="color:red;font-weight:bolder"><?php echo $class_name_to_delete;?></span> Section <span style="color:red;font-weight:bolder"><?php echo $section_name_to_delete;?></span> <span style="color:red;font-weight:bolder"><?php echo $school_name_to_delete;?></span> students</caption>
<tr>
<th>Mock ID</th>
<th>Mock Name</th>
<th>No. of sections</th>
<th>Select to <span STYLE= "color:red">DELETE</span></th>
<th>Click to SHOW Questions</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td style ="text-align:center;"> <?php echo $row['mock_id'];?></td>
<td style ="text-align:center;"> <?php echo $row['mock_name'];?></td>
<td style ="text-align:center;"> <?php echo $row['num_of_sections'];?></td>
<td style ="text-align:center;"> <input type = "checkbox" class="checkbox" name = "todelete[]" value = <?php echo $row['mock_id'];?>/></td>
<?php
echo '<td style ="text-align:center;"><a href = "pass.php?id='.$row['mock_id'].'" target ="_blank" style="text-decoration:none">SHOW</a></td>';
?>
</tr>
<?php
}
?>
</table>
<br /><br /> <br />
<input type="submit"id="removemock" value= "Remove" name= "remove" STYLE= "font-weight: bold; color: white; height: 2em; background-color: #3778BD;position:absolute;left:680px">
</form>
<form action ="school.php" method="POST">
<input type="submit" value= " Back " name= "backtable" STYLE= "font-weight: bold; color: white; height: 2em; background-color: #3778BD;position:absolute;left:600px">
</form>
请帮帮我????
试试这样:
$('.checkbox').change(function() {
// lets see how many checkboxes are selected
var checked = $('.checkbox:checked').length;
// show / hide button
if (checked > 0) {
// show button
$('#removemock').show();
} else {
//hide button
$('#removemock').hide();
}
});
默认禁用添加"disabled"属性的删除按钮然后用jquery:
$('.checkbox').on("change",function(){
if($('.checkbox:checked').length>0)
$('#removemock').prop("disabled",false);
else
$('#removemock').prop("disabled",true);
});