function checkre(checkid) {
var id = window.parent.getqry("ctrid") + "_";
var values = window.parent.opener.document.getelementbyid(id + "txt_dept_name").value;
var keys = window.parent.opener.document.getelementbyid(id + "hf_ids").value;
var ary = checkid.value.split("|");
var newsvalues = ary[0];
var newskeys = ary[1];
if (checkid.
checked) {
values = values + "," + newsvalues;
keys = keys + "," + newskeys;
}
else {
values = values.replace(new regexp("," + newsvalues), "");
keys = values.replace(new regexp("," + newskeys), "");
}
values = okd(values);
keys = okd(keys);
window.parent.opener.document.getelementbyid(id + "txt_dept_name").value = values;
window.parent.opener.document.getelementbyid(id + "hf_ids").value = keys;
return;
}
//转换成数组,去掉重复,再组合好。
function okd(str) {
var ary = str.split(",");
// 去重的算法
var json = {};
for (var i = 0; i < ary.length; i++) {
if (ary[i] != "") {
json["a" + ary[i]] = ary[i];
}
} // www.jb200.com
// 查看结果
var str2 = "";
for (var key in json) {
str2 += "," + json[key];
}
var s = str2.tostring();
/去掉第一个逗号
if (s.substr(0, 1) == ',') {
s = s.substr(1);
}
return s;
}
function add_all() {
var ck = document.getelementsbytagname("input");
for (i = 0; i < ck.length; i++) {
if (ck[i].type == "
checkbox") {
ck[i].checked = true;
checkre(ck[i]);
}
}
}
function del_all() {
var id = window.parent.getqry("ctrid") + "_";
window.parent.opener.document.getelementbyid(id + "txt_dept_name").value = "";
window.parent.opener.document.getelementbyid(id + "hf_ids").value = "";
var ck = document.getelementsbytagname("input");
for (i = 0; i < ck.length; i++) {
if (ck[i].type == "checkbox") {
ck[i].checked = false;
}
}
}
<input id='chk_pkid' type='checkbox' name='chk' onclick='checkre(this);' value='值|pkid' />