2007年9月12日星期三

全角到半角转换的 JavaScript 函数。


function whole2half(text)
{
var txt = "";
for(var i=0; i var c = text.charCodeAt(i);
if (c >= 0xff01 && c <= 0xff5e) // ASCII 0x21 - 0x7e
txt += String.fromCharCode(0x21 + c - 0xff01);
else if(c == 0x3000) //space
txt += " ";
else
txt += text.charAt(i);
}
return txt;
}

没有评论: