在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>
也面是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>
<script type="text/javascript">
改为:
<script type="text/javascript" charset="GBK">
<!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>