<%@page contentType="text/html;charset=gb2312"%>
<html>
<head>
<script language="javasctipt" type="text/javascript">
function login(){
//thisForm是form中的name
var form = document.thisForm;
if(trim(form.name.value) == ""){
window.alert("請輸入姓名!");
form.name.select();//或者form.name.focus()
return;
}
/**或像下面那樣也可以
if (trim(document.thisForm.username.value)=="")
{
alert("請填寫您的姓名!");
document.thisForm.name.focus();
return ;//false;
}
*/
if(trim(form.password.value) == ""){
window.alert("請輸入密碼!");
form.password.select();
return;
}
// 還可以做很多事情,比如在這裡又調用其他的function來觸發其他事件
form.target = "_blank";//彈出新的頁面
form.action = "isNull.jsp";//form中的action值
form.method = "post";
form.submit();//提交form
}
/** 修剪字串前後的空格 */
function trim(s) {
var count = s.length;
var st = 0; // start
var end = count-1; // end
if (s == "") return s;
while (st < count) {
if (s.charAt(st) == " ")
st ++;
else
break;
}
while (end > st) {
if (s.charAt(end) == " ")
end --;
else
break;
}
return s.substring(st,end + 1);
}
</script>
</head>
<body>
<form action="" method="post" name="thisForm" id="thisForm">
<table>
<tr>
<td><input type="text" name="name" value="" maxlength="20" style="length:30px;" /></td>
<td><input type="password" name="password" value="" maxlength="20" style="length:30px;" /></td>
<td><input type="button" name="btnFast" onclick="login();" value="登入" /></td>
</tr>
</table>
</form>
</body>
</html>