用javascript实现简单的用户登录验证
用javascript实现简单的用户登录验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript"> function check() { if(document.getElementById("username").value=="") { alert("没有输入用户名!"); return false; } else if(document.getElementById("password").value=="") { alert("没有输入密码!"); return false; } else { alert("提交成功!") return true; } } </script> <form name="form1"> <input type="text" id="username"> <input type="password" id="password" > <input type="submit" onclick="check()"> </form> </body> </html>
更多参考:牛客网 https://www.nowcoder.com/questionTerminal/f904c482f21346a6a19efd5a82655518