我也有点糊糊,不知道下面的是不是你要的效果?
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
div div{float:left;background-color:#abcabc;}
</style>
<body>
<input type="checkbox" value="A" />张<br/>
<input type="checkbox" value="B" />王<br/>
<input type="checkbox" value="C" />李<br/>
<input type="checkbox" value="D" />赵<br/>
<input type="checkbox" value="E" />赵<br/><input type="text" id="text" />
<button onclick="fun()">确定</button><script type="text/javascript">
function fun()
{
var txt = document.getElementById("text");
var checkbox = document.getElementsByTagName("input");
txt.value = "";
for(var i=0;i<checkbox.length;i++)
{
var box = checkbox[i];
if(box.type=="checkbox" && box.checked)
{
if(txt.value.indexOf(box.value)<0)
txt.value += box.value;
}
}
}
</script>
</body>
</html>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
div div{float:left;background-color:#abcabc;}
</style>
<body>
<input type="checkbox" value="A" />张<br/>
<input type="checkbox" value="B" />王<br/>
<input type="checkbox" value="C" />李<br/>
<input type="checkbox" value="D" />赵<br/>
<input type="checkbox" value="E" />赵<br/><input type="text" id="text" />
<button onclick="fun()">确定</button><script type="text/javascript">
function fun()
{
var txt = document.getElementById("text");
var checkbox = document.getElementsByTagName("input");
txt.value = "";
for(var i=0;i<checkbox.length;i++)
{
var box = checkbox[i];
if(box.type=="checkbox" && box.checked)
{
if(txt.value.indexOf(box.value)<0)
txt.value += box.value;
}
}
}
</script>
</body>
</html>
我觉得你的思路错了,假如原来A是选中的,那现在不选中了,在服务器那里,也是要把A给去掉的吧
如果是那样的话,根本就不用比较了,只需要把现在选中的值传到服务器,覆盖原来的就可以了啊比如,原来服务器上是
ABCD
现在你在客户端选择了BCD
那么不管原来服务器上的是什么,用BCD覆盖掉ABCD不成了?不知道我有没理解错……
var tong = window.showModalDialog('dep.jsp'); // 打开子页面 并传回chenckbox的值
if(tong!=null)
{
var a=tong.split(",");
var b="";
for(var i=0;i<a.length;i++)
{ if(a[i]!="")
{
if(frlist.tongid.value.indexOf(a.value)<0) // 验证选择的值是否已经存在
b += a.value+“,”; // 选择验证后的字符串
}
}
document.frlist.tongid.value=document.frlist.tongid.value+b; // 把值给赋给需要的地方
alert(b);
alert(document.frlist.tongid.value);
结果是发现 alert出来的全是undefine