javascript UTF8中文乱码
<!DOCTYPE html><html>
<body>
<h1>My First Web Page</h1>
<script>
var test="\xe6\x88\x91\xe6\x98\xaf";
document.write(test);
</script>
</body>
</html>test变量的值是汉字“我是”的UTF8编码
为什么上面这种方式显示的是乱码?该怎么修改才能显示正常 要申明html文件的编码格式,否则按浏览器自动处理
你这个需要在head内写明charset,代码如下:
<head>
<meta charset="utf-8"/>
</head> <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<h1>My First Web Page</h1>
<script>
var test="\xe6\x88\x91\xe6\x98\xaf";
document.write(test);
</script>
</body>
</html>还是不行
页:
[1]