永发信息网

javascript里表单验证不通过的时候不提交怎么弄

答案:2  悬赏:30  手机版
解决时间 2021-04-27 18:29
  • 提问者网友:浩歌待明月
  • 2021-04-27 02:59

<script language="javascript">
function cheackLogin() {
if (document.f1.login.value == "" || document.f1.login.value == null) {
alert("请输入用户名!")
} else if (document.f1.password.value == ""
|| document.f1.password.value == null) {
alert("请输入密码!")
}

}
</script>

当不输入密码和用户名的时候弹出你提示信息,但是点确定后表单还是提交了

怎么才能让表单不提交啊

最佳答案
  • 五星知识达人网友:你可爱的野爹
  • 2021-04-27 03:20
<%
dim s
randomize timer
s=Int((8999)*Rnd +1000)
%>
<!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>
<style type="text/css">
<!--
body {
background-color: #b2b2b2;
font-family: "宋体";
font-size: 12px;
}
.color {
color: #932e13;
font-weight: bold;
}
td {
border: 1px solid #949494;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=javascript>
function xxg()
{
if (document.form1.user.value==""){
alert("用户名不能为空!")
document.form1.user.focus();
return false
}
if (document.form1.password.value==""){
alert("密码不能为空!");
document.form1.password.focus();
return false
}
return true
}
function reset_form()
{
document.form1.user.value="";
document.form1.password.value="";
document.form1.s.value="";
document.form1.user.focus;
}
</script>
</head>
<body oncontextmenu="return false;" onselectstart="return false;">
<form name="form1" method="post" action="loginchk.asp" onSubmit="return xxg()">
<table width="500" height="114" border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td height="25" colspan="2"> <div align="center" class="color">管理登录</div></td>
</tr>
<tr>
<td width="108" height="25" align="center">用户名:</td>
<td width="381"> <input name="user" type="text" size="20"> </td>
</tr>
<tr>
<td width="108" height="25" align="center">密码:</td>
<td width="381"> <input name="password" type="password" size="22"> </td>
</tr>
<tr>
<td width="108" height="25" align="center">认证码:</td>
<td><input name="s" type="text" size="14">
&nbsp;<b><%=s%></b> <input maxlength=20 name="s2" size=12 type=hidden value="<%=s%>"></td>
</tr>
<tr>
<td width="108" height="25" align="center">&nbsp; </td>
<td><input type="submit" name="Submit" value=" 登 陆 "> <input type="reset" name="Submit2" value=" 取 消 " style="width: 64px" onClick="reset_form()"></td>
</tr>
</table>
</form>
</body>
</html>
全部回答
  • 1楼网友:猎心人
  • 2021-04-27 03:43
直接return false就可以了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯