ASCII码的问题

javascript中怎么得到字符的ASCII码?

是asc(varName)吗?好象不行

---------------------------------------------------------------

1<body bgcolor="#FFFFFF">
2<input onclick="test()" type="button" value="test"/>
3</body>
1<script>   
2function test(){   
3var ch = "abc" ;   
4alert("asc=="+ch.charCodeAt(0)) ;   
5}   
6</script>

试试。

---------------------------------------------------------------

ch.charCodeAt(0)是"a"的asc码
ch.charCodeAt(1)是"b"的asc码
ch.charCodeAt(2)是"c"的asc码
---------------------------------------------------------------

不对,charCodeAt返回的是unicode编码,ASCII码部分在unicode里前面加了0
中文就不行的,别指望能分成ASCII码

---------------------------------------------------------------

str.charCodeAt(0)>160

或者用escape()函数看是否含%u

Published At
Categories with Web编程
Tagged with
comments powered by Disqus