js的命名規則是比較嚴格的,要養成一個好的習慣。
經常會遇到制作登錄模塊,驗證文本框輸入是否為空就成了一個常見的問題,用js來驗證是最方便不過的了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <script> function check() { if(document.admin.admin_name.value=="") { alert("請輸入用戶名!"); document.admin.admin_name.focus(); return false; } if(document.admin.admin_pwd.value=="") { alert("請輸入密碼!"); document.admin.admin_pwd.focus(); return false; } return true; } </script> |
1 2 3 4 5 6 7 8 9 10 11 | <form name="admin" action="admin/login_check.asp" method="post" onsubmit="return check()"> <br /> 用 戶<br /> <input name="admin_name" type="text" style="width:120px; height:15px; border:1px solid #cccccc;"> <br /> 密 碼<br /> <input name="admin_pwd" type="password" style="width:120px; height:15px; border:1px solid #cccccc;"> <div style="height:5px;"></div> <input type="submit" name="submit" value="登 錄" style="border:1px dashed #cccccc; background-color:#FFFFFF; width:80px; height:25px; font-size:12px; color:#666666;"> <br /> <input type="reset" name="reset" value="重 置" style="border:1px dashed #cccccc; background-color:#FFFFFF; width:80px; height:25px; font-size:12px; color:#666666;"> </form> |