php表单不能为空,php编程,这段代码为什么不能阻止表单的提交!不管为不为空 都跳转到1.php页面啦 这是怎么回事?...

php编程,这段代码为什么不能阻止表单的提交!不管为不为空 都跳转到1.php页面啦 这是怎么回事?

关注:292  答案:5  手机版

解决时间 2021-01-12 06:43

提问者夜落花台

2021-01-11 23:45

<html>
<head>
<title>test1</title>
</head>
<body>
<script language="javascript">
function check()
{
if (document.form.xxname.value=="") 
{alert("空!不能登录!");
document.form.xxname.foucus();
return false;
}
else
{alert("asd")
return true;
}
//return true;
}
</script>
<form action="1.php" method="post" name="form" onSubmit="javascript:return check();"/>
用户名:<input type="text" name="xxname">
<input type="submit" name="submit" value="提交验证"/>
</form>
</body>
</html>

最佳答案

二级知识专家清和十五

2021-01-12 00:48

<html>
<head>
<title>test1</title>
</head>
<body>
<script language="javascript">
function check()
{
if (document.form.xxname.value=="") 
{alert("空!不能登录!");
return false;
}
//return true;
}
</script>
<form action="1.php" method="post" name="form" onSubmit="javascript:return check();"/>
用户名:<input type="text" name="xxname">
<input type="submit" name="submit" value="提交验证"/>
</form>
</body>
</html>
把 else
{alert("asd")
return true;
}
去掉就可以了,另外document.form.xxname.foucus();
这里面的foucus这个单词写错了 应该是focus
这样就可以了

全部回答

1楼守給你的承諾

2021-01-12 04:06

把document.form.xxname.foucus();

这句去掉

2楼el孤酒el

2021-01-12 03:34

你好!

那是因为你的 JS有错误所以就会直接提交

你吧 document.form.xxname.foucus(); 改成下面的

document.getElementsByName("xxname")[0].focus();

如有疑问,请追问。

3楼輓畱嶼赱

2021-01-12 01:58

οnsubmit="return check();"

4楼縱马獨歸

2021-01-12 01:04

那是因为你的 JS有错误所以就会直接提交

你吧 document.form.xxname.foucus(); 改成下面的

document.getElementsByName("xxname")[0].focus();

我要举报

如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!

推荐资讯

大家都在看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值