Javascript 如何禁用按钮直到选中复选框
我正在使用while循环中显示的复选框。但我想在选中任何复选框之前禁用我的删除按钮。我面临着困难,因为我已将复选框名称存储为数组。如何做到这一点。我的代码是Javascript 如何禁用按钮直到选中复选框,javascript,php,jquery,Javascript,Php,Jquery,我正在使用while循环中显示的复选框。但我想在选中任何复选框之前禁用我的删除按钮。我面临着困难,因为我已将复选框名称存储为数组。如何做到这一点。我的代码是 <form action="delete_mock.php" method="POST"> <table border="1" style ="width:100%"> <caption>Mock Test Details of <span style="color:red;font-weigh
<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);
});
使用按钮标记的禁用属性。我的问题的可能重复之处在于如何附加事件句柄您是否可以在JSFIDLE上复制相同的事件句柄。