用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