document.charset 这个是设置字符集的
---
对ALERT无效!alert 输出原样!

解决方案 »

  1.   

    <a href="javascript:test('中文')">中文</a>
    which charset you used when you save the HTML file?
      

  2.   

    alert(str);//alert会把str照原样输出,与字符集没有关系
      

  3.   

    <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来指定!
      

  4.   

    把你的html用editplus另存为utf-8