Zrlhappy的博客
                               从今天起, 做一个幸福的人
                                    喂马, 劈柴, 周游世界
                                    从今天起, 关心粮食和蔬菜
                                    我有一所房子, 面朝大海, 春暖花开
                                    给每一条河每一座山取一个温暖的名字
                                    我也愿面朝大海, 春暖花开……
代码如下:
 1function DBC2SBC(str)
 2{
 3 var result = '';
 4 for (i=0 ; i<str.length; i++)
 5 {
 6  code = str.charCodeAt(i);//获取当前字符的unicode编码
 7  if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
 8  {
 9   result += String.fromCharCode(str.charCodeAt(i) - 65248);//把全角字符的unicode编码转换为对应半角字符的unicode码
10  }
else if (code == 12288)//空格
11  {
12   result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
13  }
else
14  {
15   result += str.charAt(i);
16  }

17 }

18 return result;
19}

20
posted on 2007-04-09 18:01  zrlhappy  阅读(211)  评论(0)    收藏  举报