如何返回一个表示字符的Unicode值的数字?
charCodeAt()方法返回一个数字,表示给定索引处字符的Unicode值。Unicode代码点范围从0到1,114,111。前128个Unicode代码点与ASCII字符编码直接匹配。
charCodeAt(index)支持以下参数:
- index – 一个介于0和字符串长度减1之间的整数;如果未指定,默认为0。
示例
您可以尝试运行以下代码来返回表示字符的Unicode值的数字:
<html> <head> <title>JavaScript String charCodeAt() Method</title> </head> <body> <script> var str = new String( This is string ); document.write(str.charCodeAt(0) is: + str.charCodeAt(0)); document.write(<br />str.charCodeAt(1) is: + str.charCodeAt(1)); document.write(<br />str.charCodeAt(2) is: + str.charCodeAt(2)); document.write(<br />str.charCodeAt(3) is: + str.charCodeAt(3)); document.write(<br />str.charCodeAt(4) is: + str.charCodeAt(4)); document.write(<br />str.charCodeAt(5) is: + str.charCodeAt(5)); </script> </body> </html>
以上就是如何返回一个表示字符的Unicode值的数字?的详细内容,更多请关注双恒网络其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。