注册 登录
编程论坛 JavaScript论坛

JS字符编码问题

反脑控2016 发布于 2018-06-30 13:22, 1785 次点击
有人能解释一下这个程序的输出吗


<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编辑过]

0 回复
1