Method 1:
Copy codeThe Code is as follows:
Function checkRe (checkid ){
Var id = window. parent. getQry ("ctrid") + "_";
Var values = paipaiparent.opener.doc ument. getElementById (id + "txt_dept_name"). value;
Var keys = paipaiparent.opener.doc ument. 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 );
Optional bytes parent.opener.doc ument. getElementById (id + "txt_dept_name"). value = values;
Optional bytes parent.opener.doc ument. getElementById (id + "hf_ids"). value = keys;
Return;
}
// Convert to an array, remove duplicates, and then combine them.
Function okd (str ){
Var ary = str. split (",");
// Deduplication Algorithm
Var json = {};
For (var I = 0; I <ary. length; I ++ ){
If (ary [I]! = ""){
Json ["a" + ary [I] = ary [I];
}
}
// View the result
Var str2 = "";
For (var key in json ){
Str2 + = "," + json [key];
}
Var s = str2.toString ();
// Remove the first comma
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") + "_";
Optional bytes parent.opener.doc ument. getElementById (id + "txt_dept_name"). value = "";
Optional bytes parent.opener.doc ument. 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;
}
}
}
Copy codeThe Code is as follows:
<Input id = 'chk _ pkid' type = 'checkbox' name = 'chk' onclick = 'checkre (this); 'value = 'value | pkid'/>
Method 2:
Copy codeThe Code is as follows:
Function filterRepeatStr (str ){
Var ar2 = str. split (",");
Var array = new Array ();
Var j = 0
For (var I = 0; I <ar2.length; I ++ ){
If (array = "" | array. toString (). match (new RegExp (ar2 [I], "g") = null) & ar2 [I]! = ""){
Array [j] = ar2 [I];
Array. sort ();
J ++;
}
}
Return array. toString ();
}