js验证提交的表单和php验证表单哪个好
2个回答
2017-03-30 · 知道合伙人互联网行家
关注
展开全部
1、方法一
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" method="post">
用户帐号:<input type=text name="userId" size="18" value="">
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆" onclick="return check(this.form)">
</form>
</body>
</html>
JS代码:
[php] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
2、方法二
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" method="post" onsubmit="return check(this)">
用户帐号:<input type=text name="userId" size="18" value="" >
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆">
</form>
</body>
</html>
JS代码:
[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
3、方法三
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" name="myform" method="post">
用户帐号:<input type=text name="userId" size="18" value="" >
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=button name="submit1" value="登陆" onclick="check(this.form)">
</form>
</body>
</html>
JS代码:
[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" method="post">
用户帐号:<input type=text name="userId" size="18" value="">
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆" onclick="return check(this.form)">
</form>
</body>
</html>
JS代码:
[php] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
2、方法二
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" method="post" onsubmit="return check(this)">
用户帐号:<input type=text name="userId" size="18" value="" >
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆">
</form>
</body>
</html>
JS代码:
[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
3、方法三
HTML代码:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login.php" name="myform" method="post">
用户帐号:<input type=text name="userId" size="18" value="" >
<br>
登录密码:<input type="password" name="password" size="19" value=""/>
<input type=button name="submit1" value="登陆" onclick="check(this.form)">
</form>
</body>
</html>
JS代码:
[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
<script type="text/javascript">
function check(form) {
if (form.userId.value == '') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if (form.password.value == '') {
alert("请输入登录密码!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |