Home > Web Front-end > JS Tutorial > body text

javascript实现全角转半角的方法_javascript技巧

WBOY
Release: 2016-05-16 15:18:38
Original
1458 people have browsed it

本文实例讲述了javascript实现全角转半角的方法。分享给大家供大家参考,具体如下:

function fullChar2halfChar(str)
{
 var result = '';
 for (i=0 ; i= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
 {
  result += String.fromCharCode(str.charCodeAt(i) - 65248);//把全角字符的unicode编码转换为对应半角字符的unicode码
 }else if (code == 12288)//空格
 {
  result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
 }else
 {
  result += str.charAt(i);
 }
 }
 return result;
}

Copy after login

希望本文所述对大家JavaScript程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!