JQuery用戶名校驗(yàn)的具體實(shí)現(xiàn)
本實(shí)例為大家分享了JQuery用戶名校驗(yàn)功能,分享給大家供大家參考,具體內(nèi)容如下
$(document).ready(function(){}):定義頁(yè)面裝載完成時(shí),需要執(zhí)行的方法。
$()獲得頁(yè)面指定的節(jié)點(diǎn),參數(shù)是某種CSS的選擇器。返回的是一個(gè)JQuery對(duì)象,可在其上執(zhí)行JQuery方法。
val()方法可以獲得節(jié)點(diǎn)的value屬性值
html()設(shè)定某個(gè)節(jié)點(diǎn)中的html內(nèi)容
click()相應(yīng)鼠標(biāo)點(diǎn)擊事件
keyup()相應(yīng)鍵盤彈起事件
$.get()可以和服務(wù)器進(jìn)行g(shù)et方式的交互,注冊(cè)的callback方法會(huì)在數(shù)據(jù)回來(lái)的時(shí)候被調(diào)用,此方法會(huì)接收到代表服務(wù)器端返回?cái)?shù)據(jù)的一個(gè)純文本的參數(shù)
addClass()removeClass()給某個(gè)節(jié)點(diǎn)增加或刪除一個(gè)class
解決中文亂碼問(wèn)題:發(fā)送給服務(wù)器端的數(shù)據(jù)在js中做兩次encodeURI,然后在服務(wù)器端的代碼中按UTF-8的方式做一次URLDecode
主要代碼:
$.get("http://localhost:8080/JQueryStudy/UserVerify?userName=" + encodeURI(encodeURI(userName)),null, function(response){ $("#result").html(response); } )
處理的Servlet
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.linying; import java.io.IOException; import java.io.PrintWriter; import java.net.URLDecoder; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * 用戶名驗(yàn)證Servlet * @author Ying-er * @time 2010-4-25下午08:02:08 * @version 1.0 */ public class UserVerify extends HttpServlet { /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String param = request.getParameter("userName"); if (param == null || param.length() == 0) { out.println("用戶名不能為空"); } else { String userName = URLDecoder.decode(param, "UTF-8"); System.out.println(userName); if (userName.equals("Ying-er")) { out.println("用戶名[" + userName + "]已經(jīng)存在,請(qǐng)使用別的用戶名注冊(cè)"); } else { out.println("可以使用用戶名[" + userName + "]注冊(cè)"); } } } finally { out.close(); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet"> /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; }// </editor-fold> }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- jquery ajax 檢測(cè)用戶注冊(cè)時(shí)用戶名是否存在
- 基于jQuery實(shí)現(xiàn)的Ajax 驗(yàn)證用戶名是否存在的實(shí)現(xiàn)代碼
- jQuery異步驗(yàn)證用戶名是否存在示例代碼
- 基于jQuery實(shí)現(xiàn)Ajax驗(yàn)證用戶名是否存在實(shí)例
- jquery easyUI中ajax異步校驗(yàn)用戶名
- 利用jQuery.Validate異步驗(yàn)證用戶名是否存在(推薦)
- jQuery基于ajax方式實(shí)現(xiàn)用戶名存在性檢查功能示例
- jQuery+Ajax實(shí)現(xiàn)用戶名重名實(shí)時(shí)檢測(cè)
相關(guān)文章
實(shí)時(shí)監(jiān)控input框,實(shí)現(xiàn)輸入框與下拉框聯(lián)動(dòng)的實(shí)例
下面小編就為大家分享一篇實(shí)時(shí)監(jiān)控input框,實(shí)現(xiàn)輸入框與下拉框聯(lián)動(dòng)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01jQuery中closest()函數(shù)用法實(shí)例
這篇文章主要介紹了jQuery中closest()函數(shù)用法,實(shí)例分析了closest()函數(shù)的功能、定義及匹配元素的各種技巧,需要的朋友可以參考下2015-01-01jQuery+jsp實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)效果(附源碼)
這篇文章主要介紹了jQuery+jsp實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)效果,以完整實(shí)例形式分析了jQuery結(jié)合jsp讀取MySQL數(shù)據(jù)庫(kù)操作實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)效果的相關(guān)技巧,并附帶完整實(shí)例源碼供讀者下載參考,需要的朋友可以參考下2015-12-12jquery查找父元素、子元素(個(gè)人經(jīng)驗(yàn)總結(jié))
對(duì)使用js或者jquery查找父元素、子元素比較混淆的朋友可以參考下本文,因?yàn)槭莻€(gè)人總結(jié),用起來(lái)會(huì)比較方便2014-04-04jQuery實(shí)現(xiàn)的動(dòng)態(tài)伸縮導(dǎo)航菜單實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的動(dòng)態(tài)伸縮導(dǎo)航菜單,實(shí)例分析了jQuery鼠標(biāo)事件及animate、hide等方法的使用技巧,需要的朋友可以參考下2015-05-05