| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1507 人关注过本帖
标题:JS字符编码问题
只看楼主 加入收藏
反脑控2016
Rank: 4
等 级:业余侠客
威 望:2
帖 子:108
专家分:212
注 册:2016-9-2
结帖率:100%
收藏
 问题点数:0 回复次数:0 
JS字符编码问题
有人能解释一下这个程序的输出吗


<script>

var str="夜空灵雨";

document.write(str.length+":");

document.write(str.charCodeAt(-1)+"|");

document.write(str.charCodeAt(0)+"|");

document.write(str.charCodeAt(1)+"|");

document.write(str.charCodeAt(2)+"|");

document.write(str.charCodeAt(3)+"|");

document.write(str.charCodeAt(4)+"|");

document.write(str.charCodeAt(5)+"|");

document.write(str.charCodeAt(6)+"<br/>");

str="夜";

document.write(str.length+":");

document.write(str.charCodeAt(-1)+"|");

document.write(str.charCodeAt(0)+"|");

document.write(str.charCodeAt(1)+"|");

document.write(str.charCodeAt(2)+"<br/>");

str="空";

document.write(str.length+":");

document.write(str.charCodeAt(-1)+"|");

document.write(str.charCodeAt(0)+"|");

document.write(str.charCodeAt(1)+"|");

document.write(str.charCodeAt(2)+"<br/>");

str="灵";

document.write(str.length+":");

document.write(str.charCodeAt(-1)+"|");

document.write(str.charCodeAt(0)+"|");

document.write(str.charCodeAt(1)+"|");

document.write(str.charCodeAt(2)+"<br/>");

str="雨";

document.write(str.length+":");

document.write(str.charCodeAt(-1)+"|");

document.write(str.charCodeAt(0)+"|");

document.write(str.charCodeAt(1)+"|");

document.write(str.charCodeAt(2));
</script>
图片附件: 游客没有浏览图片的权限,请 登录注册



[此贴子已经被作者于2018-6-30 13:27编辑过]

搜索更多相关主题的帖子: 字符编码 str document write length 
2018-06-30 13:22
快速回复:JS字符编码问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017522 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved