代码描述:js验证表单文本框 是否为空。js验证表单文本框是否为空代码实例下载
表单验证几乎是必须的功能,有些表单验证功能很复杂,并且很绚丽,但是有些表单验证只需要满足简单的验证功能就可以了,比如验证表单项是否为空,下面就是一段能够实现功能的代码实例。 代码如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <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(); } window.onload=function(){ var theForm=document.myform; var bt=document.getElementById("bt"); bt.onclick=function(){ check(theForm) } } </script> </head> <body> <form action="#" name="myform" method="post"> 用户帐号:<input type="text" name="userId"/> 登录密码:<input type="password" name="password"/> <input type="button" value="登陆" id="bt"/> </form> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能