欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaSacript中charCodeAt()方法的使用詳解

 更新時間:2015年06月05日 12:11:27   投稿:goldensun  
這篇文章主要介紹了JavaSacript中charCodeAt()方法的使用詳解,是JS入門學(xué)習(xí)中的基本知識,需要的朋友可以參考下

 該方法返回一個數(shù)字,表示給定索引處的字符的Unicode值。

Unicode碼點范圍為0到1114111。前128個Unicode碼點的ASCII字符編碼的直接匹配。charCodeAt()將始終返回一個值小于65,536。
語法

string.charCodeAt(index);

下面是參數(shù)的詳細(xì)信息:

  •     index: 0和1之間小于字符串的長度的整數(shù); 如果未指定,默認(rèn)為0。

返回值:

返回一個數(shù)字,表示給定索引處的字符的Unicode值。如果給定的索引不是0和1之間的長度,返回NaN。
例子:

<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script type="text/javascript">
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>

這將產(chǎn)生以下結(jié)果:

str.charCodeAt(0) is:84
str.charCodeAt(1) is:104
str.charCodeAt(2) is:105
str.charCodeAt(3) is:115
str.charCodeAt(4) is:32
str.charCodeAt(5) is:105 

相關(guān)文章

最新評論