Created
February 20, 2012 04:46
-
-
Save xufan6/1867900 to your computer and use it in GitHub Desktop.
全角转半角的js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<textarea name="n" type="text" id="n" onkeyup="CtoH(this);" style="width:100%;height:100%;"></textarea> | |
<SCRIPT> | |
function CtoH(obj){ | |
var str=obj.value; | |
var result=""; | |
for (var i = 0; i < str.length; i++){ | |
if (str.charCodeAt(i)==12288){ | |
result+= String.fromCharCode(str.charCodeAt(i)-12256); | |
continue; | |
} | |
if (str.charCodeAt(i)!=65292 && str.charCodeAt(i)>65280 && str.charCodeAt(i)<65375) result+= String.fromCharCode(str.charCodeAt(i)-65248); | |
else result+= String.fromCharCode(str.charCodeAt(i)); | |
} | |
obj.value=result; | |
} | |
</SCRIPT> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment