[JavaScript] 全角转换为半角函数 →→→→→进入此内容的聊天室

来自 , 2020-08-26, 写在 JavaScript, 查看 105 次.
URL http://www.code666.cn/view/20f07591
  1. function ToCDB(str){
  2.     var result = '';
  3.     for(var i=0; i < str.length; i++){
  4.         code = str.charCodeAt(i);
  5.         if(code >= 65281 && code <= 65374){
  6.               result += String.fromCharCode(str.charCodeAt(i) - 65248);
  7.         }else if (code == 12288){
  8.               result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  9.         }else{
  10.               result += str.charAt(i);
  11.         }
  12.     }
  13.     return result;
  14. }

回复 "全角转换为半角函数"

这儿你可以回复上面这条便签

captcha