2个回答
推荐于2016-06-29 · 知道合伙人软件行家
关注
展开全部
一般来说,这种功能编写js代码来完成效果好于用php编写,以下是一个相对比较完整的用户注册示例:
<!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 validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}
}
}
function validate_username(field,alerttxt)
{
with (field)
{
apos=value.length
if (apos<6||apos>12)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_pass(field,alerttxt)
{
with (field)
{
apos=value.length
if (apos<6||apos>10)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(username,"用户名不能为空!")==false)
{fname.focus();return false}
if (validate_required(password,"密码不能为空!")==false)
{Password.focus();return false}
if (validate_pass(password,"密码不能小于6位或大于10位!")==false)
{password.focus();return false}
if (validate_username(username,"用户名不能小于6位或大于10位!")==false)
{username.focus();return false}
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" onsubmit="return validate_form(this)" action="reg.php">
<table width="344" height="136" border="0" align="center" cellpadding="2" cellspacing="2">
<td width="55" height="35" align="right">用户:</td>
<td width="275"><input type="text" name="username" id="username" width="150" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td height="35"><input type="password" name="password" id="password" width="150" /></td>
</tr>
<tr>
<td height="45" colspan="2" align="center"><input type="submit" value="注册" /> </td>
</tr>
</table>
</form>
</body>
</html>
<!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 validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}
}
}
function validate_username(field,alerttxt)
{
with (field)
{
apos=value.length
if (apos<6||apos>12)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_pass(field,alerttxt)
{
with (field)
{
apos=value.length
if (apos<6||apos>10)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(username,"用户名不能为空!")==false)
{fname.focus();return false}
if (validate_required(password,"密码不能为空!")==false)
{Password.focus();return false}
if (validate_pass(password,"密码不能小于6位或大于10位!")==false)
{password.focus();return false}
if (validate_username(username,"用户名不能小于6位或大于10位!")==false)
{username.focus();return false}
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" onsubmit="return validate_form(this)" action="reg.php">
<table width="344" height="136" border="0" align="center" cellpadding="2" cellspacing="2">
<td width="55" height="35" align="right">用户:</td>
<td width="275"><input type="text" name="username" id="username" width="150" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td height="35"><input type="password" name="password" id="password" width="150" /></td>
</tr>
<tr>
<td height="45" colspan="2" align="center"><input type="submit" value="注册" /> </td>
</tr>
</table>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询