當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS的小例子
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>表單驗證</title></head><body><script type="text/javascript">window.onload = function(){var flag1 =false;var flag2 =false;//用戶名document.getElementById("usernameid").onblur = function(){var username = document.getElementById("usernameid").value;var regExp = /^[0-9a-zA-Z]{6,14}$/var ok = regExp.test(username);var reminder = document.getElementById("usernamereminder");if(!ok){reminder.innerHTML="<font color='red' size='1px'>用戶名非法</font>";flag1 = false;}else{reminder.innerHTML="<font color='red' size='1px'>用戶名合法</font>";flag1=true;}}document.getElementById("usernameid").onfocus = function(){document.getElementById("usernamereminder").innerHTML="<font color='black' size='1px'>用戶名由6-14位的數字和字母組成</font>";}//確認密碼document.getElementById("passwordconfirmid").onblur = function(){var pwd1 = document.getElementById("passwordid").value;var pwd2 = document.getElementById("passwordconfirmid").value;if(pwd1 == pwd2){document.getElementById("passwordreminder").innerHTML="<font color='red' size ='1px' >確認密碼和密碼一致</font>"flag2=true;}else{document.getElementById("passwordreminder").innerHTML="<font color='red' size ='1px' >確認密碼和密碼不一致</font>"flag2=false;}}document.getElementById("button").onclick=function(){if(flag1 & flag2){document.getElementById("form").action="https://www.baidu.com";}else{document.getElementById("form").action="javascript:void(0)";}}}</script><form action="" method="get" id="form">用戶名<input type="text" name="username" id="usernameid" value="" /><span id="usernamereminder"></span><br>密碼<input type="password" name="password" id="passwordid" value="" /><br>確認密碼<input type="password" name="" id="passwordconfirmid" value="" /><span id="passwordreminder"></span><br><input type="submit" name="" id="button" value="提交" /></form></body>
</html>
總結
- 上一篇: java jpanel setbackg
- 下一篇: gradle idea java ssm