構建一個登陸頁面實現驗證跳轉
阿新 • • 發佈:2018-12-21
<form action="https://www.baidu.com" onsubmit="return fc()"> <input type="text" name="username" value="vvv" /> <input type="password" name="password" /> <button type="submit">登入</button> </form> <script> function fc() { var fs = true var inp1 = document.querySelectorAll("input")[0]; var inp2 = document.querySelectorAll("input")[1]; var myInp1 = inp1.value; var myInp2 = inp2.value; if (myInp1 == "zs") { if (myInp2 == "12345") { alert("輸入正確"); return fs; } else { fs = false; alert("密碼錯誤"); return fs; } } else { fs = false; alert("使用者名稱錯誤"); return fs; } } </script>