在HTML页面<script>标签 里弹出的文字乱码
也面是gb2312  JS 是UTF-8的 HTML里的中文都是转了UTF-8   
  怎么解决乱码   加了charset  也诶用<script type="text/javascript"> 
function beforeSubmit(form1){
if(form1.username.value==''){
alert('用户不能为空 !');
form1.username.focus();
return false;
}
if(form1.password.value==''){
alert('密码不能为空!');
form1.password.focus();
return false;
}
if(form1.password.value.length<6){
alert('密码至少为6位,请重新输入!');
form1.password.focus();
return false;
}return true;
}
</script>

解决方案 »

  1.   

    html文件、js文件以及html文件中的meta标签设置的编码要统一。
      

  2.   

    在这</script> 怎么把中文转换了!不乱码!
      

  3.   

    记事本打开 另存为 编码选 与 页面meta定义的编码 一致。
      

  4.   

    楼主试下:
    <script type="text/javascript"> 
    改为:
    <script type="text/javascript" charset="GBK"> 
      

  5.   

    这个不会乱码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <script type="text/javascript">  
    function beforeSubmit(form1){
    if(form1.username.value==''){
    alert('用户不能为空 !');
    form1.username.focus();
    return false;
    }
    if(form1.password.value==''){
    alert('密码不能为空!');
    form1.password.focus();
    return false;
    }
    if(form1.password.value.length<6){
    alert('密码至少为6位,请重新输入!');
    form1.password.focus();
    return false;
    }return true;
    }
    </script>
    </head>
    <form id="form1" onsubmit="beforeSubmit(this);">
    用户:
    <input type="text" id="username"/>
    <br />
    密码:
    <input type="password" id="password"/>
    <input type="submit" value="提交" />
    </form>
    <body>
    </body>
    </html>
      

  6.   

    可以将js中的中文进行unicode编码处理,就可以适应任何页面编码了
      

  7.   

    刚写错了,不是unicode编码,是16进制转换,比如alert("\u9ad8\u8d35\u6a58\u9ec4")