<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><script type="text/javascript">function focus_username(){ //獲取id=result_username的對象 var resultObj = document.getElementById("result_username"); //寫入提示信息 resultObj.innerHTML = "請輸入你的用戶名"; resultObj.style.color = "gray";}function focus_userpwd(){ //獲取id=result_userpwd的對象 var resultObj = document.getElementById("result_userpwd"); //寫入提示信息 resultObj.innerHTML = "請輸入你的密碼"; resultObj.style.color = "gray";}function blur_username(){ //獲取id=result_username的對象 var resultObj = document.getElementById("result_username"); //用戶名的驗證 if(document.form1.username.value=="") { resultObj.innerHTML = "<font color='red'>用戶名不能為空!</font>"; return false; }else if(document.form1.username.value.length<5 || document.form1.username.value.length>20) { resultObj.innerHTML = "<font color='red'>用戶名長度必須介于5-20個字符之間!</font>"; return false; }else { resultObj.innerHTML = "<img src='images/ok.gif' />"; return true; }}function blur_userpwd(){ //獲取id=result_userpwd的對象 var resultObj = document.getElementById("result_userpwd"); //密碼的驗證 if(document.form1.userpwd.value=="") { resultObj.innerHTML = "<font color='red'>密碼不能為空!</font>"; return false; }else if(document.form1.userpwd.value.length<5 || document.form1.userpwd.value.length>20) { resultObj.innerHTML = "<font color='red'>密碼長度必須介于5-20個字符之間!</font>"; return false; }else { resultObj.innerHTML = "<img src='images/ok.gif' />"; return true; }}function checkForm(){ var flag_username = blur_username(); var flag_userpwd = blur_userpwd(); if(flag_username==true && flag_userpwd==true) { return true; }else { return false; }}</script></head><body><form name="form1" method="post" action="login.php" onsubmit="return checkForm()"><table width="600" border="1" bordercolor="#ccc" align="center" rules="all" cellpadding="5"> <tr> <td width="100" align="right">用戶名:</td> <td><input type="text" name="username" onfocus="focus_username()" onblur="blur_username()" /></td> <td width="300"><div id="result_username"></div></td> </tr> <tr> <td align="right">密碼:</td> <td><input type="password" name="userpwd" onfocus="focus_userpwd()" onblur="blur_userpwd()" /></td> <td><div id="result_userpwd"></div></td> </tr> <tr> <td> </td> <td colspan="2"> <input type="submit" value="提交表單" /> <input type="reset" value="重新填寫" /> </td> </tr></table></form></body></html>
輸入框未設(shè)置邊框,怎么會自動變色?求解釋
慕慕9086560
2016-10-31 11:33:23