生活随笔
收集整理的這篇文章主要介紹了
注册demo,使用jQuery异步验证账号是否存在
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jQuery驗證賬號是否存在form表單提交判斷,失焦判斷
function check_UserId() {$userId
= $("#userId").val();$
.post("checkUserId","userId=" + $userId
,function (result
) { if (result
== "true") { alert("賬號存在!");document
.getElementById("sub").disabled
= true;}if (result
== "false") {document
.getElementById("sub").disabled
= false;}},"text");}
<%@ page language
="java" import="java.util.*" pageEncoding
="UTF-8"%>
<%
String path
= request
.getContextPath();
String basePath
= request
.getScheme()+"://"+request
.getServerName()+":"+request
.getServerPort()+path
+"/";
%>
<html><head><base href
="<%=basePath%>"><title>My JSP
'index.jsp' starting page
</title
><meta http
-equiv
="pragma" content
="no-cache"><meta http
-equiv
="cache-control" content
="no-cache"><meta http
-equiv
="expires" content
="0"> <meta http
-equiv
="keywords" content
="keyword1,keyword2,keyword3"><meta http
-equiv
="description" content
="This is my page"><script type
="" src
= "scripts/jquery-1.8.3.min.js"></script
><script type
="text/javascript">function
check_form() {var els
= document
.getElementsByTagName("input");for (var i
= 0; i
< els
.length
; i
++) {if (typeof(els
[i
].getAttribute("onblur")) == "string" || typeof(els
[i
].getAttribute("onblur")) == "function") {if (!check_item(els
[i
])) {return false;}}}return true;}function
check_item(obj
) {var msgBox
= obj
.parentNode
.getElementsByTagName("span")[0];var val
= obj
.value
.trim();var name
= obj
.name
;switch (name
) {case "userId":if (val
== "" || val
== null
) {msgBox
.innerText
= "填寫用戶名";return false;} else {check_UserId();} break;case "userPwd":if (val
== "" || val
== null
) {msgBox
.innerText
= "填寫密碼";return false;} }return true;}function
focus_item(obj
) {var msgBox
= obj
.parentNode
.getElementsByTagName("span")[0];msgBox
.innerText
= "";}</script
></head
><body><form action
="registerServlet" method
="post" onsubmit
="return check_form()"><table><tr><td>userId
: <input type
="text" name
="userId" id
="userId" onfocus
="focus_item(this)" onblur
="check_item(this)"/><span></span
></td
><td>userPwd
:<input type
="password" name
="userPwd" onfocus
="focus_item(this)" onblur
="check_item(this)"/><span></span
></td
></tr
><tr><td><input type
="submit" value
="注冊" id
="sub" disabled
="disabled"/></td
><td><input type
="reset" value
="重置"/></td
> </tr
></table
></form
></body
>
</html
>
總結
以上是生活随笔為你收集整理的注册demo,使用jQuery异步验证账号是否存在的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。