有关document.charset的问题?
<html>
<head>
<title> New Document </title>
<meta http-equiv="content-type" content="text/html; charset=gbk">
</head>
<script>
function test(s){
alert(document.charset);
alert(s);
document.charset="utf-8";
alert(document.charset);
alert(s);
}
</script>
<body>
<body>
<a href="javascript:test('中文')">中文</a>
</body>
</html>
在js中设置了utf-8,不知为什么alert(s)出来的不是utf-8编码的字符,不知我用对了没有?
如果没有用对,将怎么处理?
问题点数:100、回复次数:5Top
1 楼sanshisong(三师兄)回复于 2006-05-03 21:42:31 得分 0
document.charset 这个是设置字符集的
---
对ALERT无效!alert 输出原样!
Top
2 楼jiangsheng(蒋晟.Net[MVP])回复于 2006-05-04 00:22:22 得分 0
<a href="javascript:test('中文')">中文</a>
which charset you used when you save the HTML file?Top
3 楼DeluxWorld(曾经的你)回复于 2006-05-04 10:28:50 得分 0
alert(str);//alert会把str照原样输出,与字符集没有关系Top
4 楼SharpBug(@)回复于 2006-05-04 10:43:30 得分 0
<html>
<head>
<title> New Document </title>
<meta http-equiv="content-type" content="text/html; charset=gbk">
</head>
<script>
function test(s){
alert(document.charset);
alert(s);
document.charset="utf-8";
alert(document.charset);
alert(s);
document.getElementById("d").innerHTML = s;
document.getElementById("d1").innerText = s;
}
</script>
<body>
<a href="javascript:test('中文')">中文</a>
<div id="d"></div>
<div id="d1"></div>
</body>
</html>
就算不用alert,将s的值赋到div上,也还是gbk字符集的,而不是utf-8字符集的,我的用意是希望通过document.charset来改变以后的字符输出由js改变,不用meta来指定!
Top
5 楼DeluxWorld(曾经的你)回复于 2006-05-04 11:46:23 得分 0
把你的html用editplus另存为utf-8Top




