日期:2014-05-17  浏览次数:20711 次

jquery做全选反选
下面是我的代码
麻烦大家帮帮我啊
  <tr bgcolor="#c30" bordercolor="#c30" >
<th width="10%"> 
<input type="checkbox" name="blodidall" id="checkboxids" onclick="isCheckAll()"/>博客id</th>
<th width="30%">博客标题</th>
<th width="20%">博客内容</th>
<th width="10%">博客类型</th>
<th width="10%">博客时间</th>
<th width="10%">操作</th> </tr>
  <%
  List<BlogDTO> list=(List<BlogDTO>)request.getAttribute("list");
  int pageno=(Integer)request.getAttribute("pageno");
  int totalpage =(Integer)request.getAttribute("totalpage");
  for(int i=0;i<list.size();i++){
BlogDTO bdto=list.get(i);
  %>
<tr bordercolor="#c30" onmouseover="this.style.backgroundColor='fff'"; onmouseout="this.style.backgroundColor='c30'"; style="cursor:pointer;">
  <td> <input type="checkbox" name="blodid" id="checkboxid" /><%=bdto.getBlog_id()%></td>
  <td> <%=bdto.getBlog_title()%></td>
  <td> <%=bdto.getBlog_content()%></td>
  <td> <%=bdto.getBlog_id()%></td>
  <td> <%=bdto.getBlog_time()%></td>
  <td> <a href="FindByBlogIdServlet?blog_id=<%=bdto.getBlog_id() %>" style="#c30">修改</a>&nbsp;&nbsp;<a href="DeleteBlogServlet?blog_id=<%=bdto.getBlog_id() %>" style="#fff">删除</a></td>
  </tr>

------解决方案--------------------
这有一个例子,直接js,没有使用jquery,但意思是一样的:
//选择取消全部
function selectAll(check)
{
var elems = document.getElementsByName("Ids");//取出全部name=ids的input,这里为type=checkbox的input

for(var i=0;i<elems.length;++i)//循环
{
if(check)
elems[i].checked="checked";
else
elems[i].checked="";
}
}
------解决方案--------------------

<script type="text/javascript">
 function isCheckAll(){
 //将所有name为blodid的元素选中。
 $("input[name='blodid']").attr("checked", true);

 }
</script>

------解决方案--------------------
[Quote=引用:]
var flag=true;
$("#checkboxids").click(function(){
alert(flag);
//alert("ok");
if(flag=true){
$('input[type="checkbox"]').attr("checked", true);
flag=false;
}
if(flag=false){
//alert("111");
……/Quote] 
楼主 你写的单双引号有问题 你看看jquery官方api,都有实例的,要规范些。
$("input[type='checkbox']").attr("checked", true); 还有flag == true 两个=号
------解决方案--------------------
这个我也说不太清楚呵呵,反正复选框这里用attr是没办法获取到checked属性的状态的
还有另一种方法is(":checked")也是可以的,你记住就行了
------解决方案--------------------
//复选框组和全选关联
$('input[type=checkbox][name=blodid]').click(function(){
var flag=true;
$('input[type=checkbox][name=blodid]').each(function(){
if(!this.checked){
flag = false;
}
});

if( flag ){
$('#checkboxids').attr('checked', true );
}else{
$('#checkboxids').attr('checked', false );