1 function chgCase(sStr,iCase){
2 if(typeof sStr != "string" || sStr.length <= 0 || !(iCase === 0 || iCase == 1)){
3 return sStr;
4 }
5 var i,oRs=[],iCode;
6 if(iCase){/*半->全*/
7 for(i=0; i<sStr.length;i+=1){
8 iCode = sStr.charCodeAt(i);
9 if(iCode == 32){
10 iCode = 12288;
11 }else if(iCode < 127){
12 iCode += 65248;
13 }
14 oRs.push(String.fromCharCode(iCode));
15 }
16 }else{/*全->半*/
17 for(i=0; i<sStr.length;i+=1){
18 iCode = sStr.charCodeAt(i);
19 if(iCode == 12288){
20 iCode = 32;
21 }else if(iCode > 65280 && iCode < 65375){
22 iCode -= 65248;
23 }
24 oRs.push(String.fromCharCode(iCode));
25 }
26 }
27 return oRs.join("");
28 }