关于input checkbox;类型的全选和全不选
本帖最后由 Closer 于 2016-1-20 17:37 编辑<table>
<thead>
<tr>
<th>
<input type="checkbox" name="a">
</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $val):?>
<tr><td><input type="checkbox" name="b[]">
<?php endforeach;?>
</tbody>
<script src="/js/jquery.min.js"></script>
<script type="text/javascript">
//方法1:----------------------------------------------
$(function(){
$("input").click(function(){
$(":checkbox").prop("checked",this.checked);
})
})
//方法2-----------------------------------
$("input").click(function(){
if(this.checked){
$("tbody input").each(function(){
this.checked=true;
});
}else{
$("tbody input").each(function(){
this.checked=false;
});
}
})
</script> 第一个方法只能用prop,那个attr不行,也不知道为什么。大家还有什么好的办法可以写出来,大家交流。
页:
[1]