Php 全选复选框选项只工作一次,然后不工作
我有一堆复选框,我正试图得到一个去/全选按钮为他们工作。复选框通过标签设置为图像,并使用jquery slidetoggle位于可扩展的div中,我使用的是引导,不确定这是否重要 此外,复选框本身是通过一个php循环生成的,因为有大约30件事情我希望以这种方式保存,而不必逐个执行,另外这意味着我可以向数据库中添加新的复选框,并且可以正常工作。我这么说,因为我觉得这个php循环可能是个问题 我当前的代码结构,包括复选框和expand div的脚本如下所示:Php 全选复选框选项只工作一次,然后不工作,php,jquery,html,checkbox,Php,Jquery,Html,Checkbox,我有一堆复选框,我正试图得到一个去/全选按钮为他们工作。复选框通过标签设置为图像,并使用jquery slidetoggle位于可扩展的div中,我使用的是引导,不确定这是否重要 此外,复选框本身是通过一个php循环生成的,因为有大约30件事情我希望以这种方式保存,而不必逐个执行,另外这意味着我可以向数据库中添加新的复选框,并且可以正常工作。我这么说,因为我觉得这个php循环可能是个问题 我当前的代码结构,包括复选框和expand div的脚本如下所示: <script>
<script>
$(document).ready(function(){
$(".fliplogo").click(function(){
$(".panellogo").slideToggle("slow");
});
});
</script>
<script>
$(document).ready(function(){
$('input[name="all"],input[name="title"]').bind('click', function(){
var status = $(this).is(':checked');
$('input[type="checkbox"]', $(this).parent('li')).attr('checked', status);
});
});
</script>
<div class="navbar navbar-inverse fliplogo" style="padding:5px; color:white">
Car Manufacture
</div>
<div id="sites" class="navbar navbar-inverse panellogo" style="display:none; min-height:0px">
<li>
<input type="checkbox" name="all" id="all" style="color:white" checked/>
<label for='all' style="color:white">Select All Manufactures
</label><br>
<?php
$webserver = 'localhost';
$administrator = 'root';
$password = '';
$db_name = 'cdb';
$db = mysqli_connect($webserver, $administrator, $password, $db_name)
or die('Error connecting');
$query = "SELECT DISTINCT make,logo FROM cars";
$result = mysqli_query($db, $query)
or die("Error in query: '$query'");
$row = mysqli_fetch_assoc($result);
$i = 0;
while($row = mysqli_fetch_assoc($result))
{
$i++;
echo'
<input type="checkbox" style="display:none" id="'.$i.'" value="'.$row['make'].'" checked/>
<label for="'.$i.'"><img src="'.$row['logo'].'" style="height:50px; width:50px"/>
</label>
';
}
?>
</li>
</div>
这把小提琴显示了我正在使用的全选代码:
这把提琴用于复选框:
即使我在我的网站上独自尝试,只要使用“全部”复选框fiddle中的代码,它的行为也是一样的。无论我将小提琴上的代码放在何处,它的行为都是一样的,工作一次,然后停止。检查/取消检查按钮将工作一次,然后停止。如果它们在开始时都被选中,它将取消选中它们,它将选择它们,然后取消帮助。。。就这样
非常感谢所有帮助-Tom对我来说很好…可以根据我的需要多次选中/取消选中所有代码。@bryan无论我从这里将代码放置在何处:其行为相同,单独作为基本复选框,它将工作一次,然后停止。也许我有点困惑,但我可以根据我的需要多次单击所有,然后它选择/取消选择所有。。。不知道问题出在哪里。
.input_hidden {
position: absolute;
left: -9999px;
}
#sites label {
display: inline-block;
cursor: pointer;
}
#sites label:hover {
background-color: #500000;
}
#sites label img {
padding: 3px;
}
input[type=checkbox]:checked + label img {
background-color: #ccc;
}