js驗證表單也存在中文亂碼
阿新 • • 發佈:2019-02-03
把pageEncoding="utf-8" 去掉,另外2個地方全換成gb2312
<%@ page language="java" contentType="text/html; charset=gb2312"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>西安小升初</title> <link href="CSS/style.css" type="text/css" rel="stylesheet"> <script src="JS/validate.js" language="javascript" type="text/javascript"></script> <style type="text/css"> <!-- body { background-image: url(images/bg_01.gif); } --> </style> </head>
validate.js
function userCheck() { // 使用者登入驗證
if (document.form1.account.value == "") {
window.alert("請輸入使用者名稱稱");
return false;
}
if (document.form1.password.value == "") {
window.alert("請輸入使用者密碼");
return false;
}
return true;
}
<form name="form1" method="post" action="ConsumerServlet?method=0&sign=0" onSubmit="return userCheck()">