JavaSacript中charCodeAt()方法的使用詳解
該方法返回一個(gè)數(shù)字,表示給定索引處的字符的Unicode值。
Unicode碼點(diǎn)范圍為0到1114111。前128個(gè)Unicode碼點(diǎn)的ASCII字符編碼的直接匹配。charCodeAt()將始終返回一個(gè)值小于65,536。
語(yǔ)法
string.charCodeAt(index);
下面是參數(shù)的詳細(xì)信息:
- index: 0和1之間小于字符串的長(zhǎng)度的整數(shù); 如果未指定,默認(rèn)為0。
返回值:
返回一個(gè)數(shù)字,表示給定索引處的字符的Unicode值。如果給定的索引不是0和1之間的長(zhǎng)度,返回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)文章
在JavaScript中使用對(duì)數(shù)Math.log()方法的教程
這篇文章主要介紹了在JavaScript中使用對(duì)數(shù)Math.log()方法的教程,是JS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-06-06
JavaScript中g(shù)etUTCSeconds()方法的使用詳解
這篇文章主要介紹了JavaScript中g(shù)etUTCSeconds()方法的使用詳解,是JS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-06-06
關(guān)于不同頁(yè)面之間實(shí)現(xiàn)參數(shù)傳遞的幾種方式討論
下面小編就為大家?guī)?lái)一篇關(guān)于不同頁(yè)面之間實(shí)現(xiàn)參數(shù)傳遞的幾種方式討論。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02
JavaScript中的prototype和constructor簡(jiǎn)明總結(jié)
一直沒(méi)弄清楚JavaScript中的prototype和constructor屬性,今天看了看書,總算有點(diǎn)眉目了2014-04-04
javascript中interval與setTimeOut的區(qū)別示例介紹
這篇文章主要介紹了javascript中interval與setTimeOut的區(qū)別,需要的朋友可以參考下2014-03-03
深入解析JavaScript編程中的this關(guān)鍵字使用
這篇文章主要介紹了深入解析JavaScript編程中的this關(guān)鍵字使用,是JS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-11-11
JavaScript_object基礎(chǔ)入門(必看篇)
下面小編就為大家?guī)?lái)一篇JavaScript_object基礎(chǔ)入門(必看篇)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06

