提交表單時執行func方法實現代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:
<%@ page contentType="text/html; charset=utf-8"%>
<!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>使用者註冊</title>
<script language="javascript">
<!--
function MyForm(){
msg.innerHTML="debug::in function";
var username = document.form1.username.value;
var msg = document.getElementById("msg");
if(username.length==0){
msg.innerHTML="[ 提示:使用者名稱不可為空! ]";
document.form1.username.focus();
return false;
}
var pass = document.form1.password.value;
if(pass.length==0){
msg.innerHTML="[ 提示:密碼不可為空! ]";
document.form1.password.focus();
return false;
}
var pass1 = document.form1.password1.value;
if(pass1.length==0){
msg.innerHTML="[ 提示:確認密碼不可為空! ]";
document.form1.password1.focus();
return false;
}
if(pass1!=pass){
msg.innerHTML="[ 提示:您兩次輸入的密碼不一致! ]";
document.form1.passwoid.focus();
return false;
}
var mail = document.form1.mail.value;
if(mail.length==0){
msg.innerHTML="[ 提示:E_mail不可為空! ]";
document.form1.mail.focus();
return false;
}
var i = form1.mail.value.indexOf("@");
var j = form1.mail.value.indexOf(".");
if((i<0)||(j<0)||(i-j>0))
{
msg.innerHTML="[ 提示:您輸入的E_mail格式不正確,請正確輸入! ]";
document.form1.mail.focus();
return false;
}
msg.innerHTML="";
return true;
}
-->
</script>
</head>
<body onload="document.form1.username.focus()">
<form id="form1" name="form1" method="post" action="" onsubmit="return MyForm()">
<table width="389" border="1" align="center" cellpadding="5">
<tr>
<td colspan="2"><div align="center">使用者註冊<br /></div></td>
</tr>
<tr>
<td colspan="2" align="center" bordercolor=""
bgcolor="">
<font color="red"><span id="msg">${error}</span> </font>
</td>
</tr>
<tr>
<td width="71">使用者名稱:</td>
<td width="286"><label>
<input name="username" type="text" id="username" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>使用者密碼:</td>
<td><label>
<input name="password" type="password" id="password" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>重複密碼:</td>
<td><label>
<input name="password1" type="password" id="password1" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>電子郵件:</td>
<td><label>
<input name="mail" type="text" id="mail" size="25" />
</label>
*(必填)</td>
</tr>
<tr>
<td>電話:</td>
<td><label>
<input name="tel" type="text" id="tel" size="22" />
</label></td>
</tr>
<tr>
<td>QQ:</td>
<td><label>
<input name="qq" type="text" id="qq" size="22" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="註冊" />
<input type="reset" name="Submit2" value="重設" />
</div>
</label></td>
</tr>
</table>
</form>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.