您的位置:首页 > 其它

自动全选和自动去除全选

2013-08-07 13:44 127 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
String app = request.getContextPath();
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>发送列表</title>
<link rel="stylesheet" type="text/css" href="<%=app %>/css/base.css" />

<script language="javascript">

//复选框全选的方法
function selAll(obj)
{
var o=document.getElementsByName("che");
for(var i=0;i<o.length;i++)
{
if(obj.checked==true)
o[i].checked=true;
else
o[i].checked=false;
}
}

//点击取消按钮的方法
function btnCancel()
{
window.close();
}
//得到选中的手机号
function getCellValue()
{
var all=document.getElementsByName("che");
var len=document.getElementsByName("che").length;
var fin="";
var phone="";
for(var i=1;i<len;i++)
{
if(all[i].checked==true)
{
var chId=parseInt(all[i].value);
var rowNum=chId;
var m=document.getElementById("table").rows[rowNum].cells[4].innerHTML;
phone=phone+m+",";
}
}
fin=phone.substring(0,phone.length-1);
if(fin=="" || fin==null){
alert("您还没有选择客户!");
return;
}
window.returnValue=fin;
window.close();
}
//判断是否全部被选中,如果选中全选复选框被选中,反之未被选中
function selFirst()
{
var o=document.getElementsByName("che");
var count=0;
var num=0;
for(var i=0;i<o.length-1;i++)
{
if(o[i+1].checked==true)
{
count++;
}
if(o[i+1].checked==false)
{
num++;
}
}
if(count==o.length-1)
{
o[0].checked=true;
}
if(num>0)
{
if(o[0].checked==true)
{
o[0].checked=false;
}
}
}
</script>
</head>
<body leftmargin="5" topmargin="5" >
<form action="" method="post" target="_self">
<table width="700" border="0" id="table" cellpadding="2" cellspacing="1" class="maintable" align="center" style="margin-top:8px" >
<tr class="tr1">
<td height="24" colspan="7"  align="center" > <strong>发送列表</strong>
</tr>
<tr align="center" class="tr2" >
<td><input name="che" type="checkbox" value="1" onclick="selAll(this)"></td>
<td width="127">编号</td>
<td width="81">客户名称</td>
<td width="81">身份证</td>
<td width="81">手机号</td>
<td width="119">卡号</td>
<td width="85">业务状态</td>
</tr>
<s:set var="num" value="2"></s:set>
<s:iterator id="customer" value="customerInfos">
<tr class="tr2" align="center" >
<td><input name="che" type="checkbox" onclick="selFirst()" value="<s:property value="#num"/>"/></td>
<td><s:property value="#customer.customerID"/></td>
<td><s:property value="#customer.userName"/></td>
<td><s:property value="#customer.cardID"/></td>
<td><s:property value="#customer.phone"/></td>
<td><s:property value="#customer.cardNum"/></td>
<td><s:property value="#customer.isState"/></td>
</tr>
<s:set var="num" value="#num+1"></s:set>
</s:iterator>

<tr align="center">
<td colspan="7" >
<input name="" type="button" onclick="getCellValue()" value="确定" style="height:25px;width:70px;">
<input name="" type="button" value="取消" onclick="btnCancel()"  style="height:25px;width:70px;">
</td>
</tr>
</table>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: