<html>
<head>
<title>多媒體實驗</title>
<!--<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="skin/player4.css" rel="stylesheet" type="text/css" id="cssfile" />-->
<script language="javaScript">
function userLogin(obj){
var userName=document.mediaForm.userName.value;
var userPwd=document.mediaForm.userPwd.value;
var flag=true;
if(userName==""){
alert("用戶名不能爲空");
flag=false;
}
if(userPwd==""){
alert("用戶密碼不能爲空");
flag=false;
}
if(flag){
document.mediaForm.click_action.value=obj.value;
document.mediaForm.action="http://127.0.0.1:80/cgi-bin/FirstEmbedPrj.cgi";
document.mediaForm.submit();
}
}
</script>
</head>
<body bgcolor="#999999">
<center>
<form name="mediaForm" method="post" action="">
<br /><br /><br /><br />
<table cellpadding="2" cellspacing="2" align="center" bgcolor="#FF0000" style="color:#00FF00" border="2">
<tr>
<td colspan="2" align="center">用戶登陸</td>
</tr>
<tr >
<td>用戶名:</td>
<td><input type="text" name="userName" value=""/></td>
</tr>
<tr>
<td>密 碼:</td>
<td><input type="password" name="userPwd" value=""/></td>
</tr>
<tr>
<td align="center"><input type="submit" name="sub" value="login" οnclick="userLogin(this);"/></td>
<td align="center"><input type="button" name="smt" value="login_sub" οnclick="userLogin(this);"/></td>
<td align="center"><input type="hidden" name="click_action" value=""/></td>
<td align="center"><input type="reset" name="ret" value="reset"/></td>
</tr>
</table>
</form>
</center>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------
從中得到的知識爲:
1.當提交時type="submit"的按鈕的值會傳到服務器中,形式爲:name=value,上面爲sub=login
2.當提交時type="button"的按鈕的值不會傳到服務器中
3.當將form改爲:<form name="mediaForm" method="post" action="http://127.0.0.1:80/cgi-bin/FirstEmbedPrj.cgi">
(a)點擊type="submit"的按鈕提交時,即使表單驗證不成功,照樣會提交表單。當表單action爲空時
驗證不成功時,也會提交表單,不過效果相當於刷新該頁面而已。
(b)點擊type="button"的按鈕提交時,表單驗證不成功時,即使表單action不爲空,也不會提交