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)鍵盤(pán)彈起事件
$.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)文章
手機(jī)移動(dòng)端實(shí)現(xiàn) jquery和HTML5 Canvas的幸運(yùn)大獎(jiǎng)盤(pán)特效
這篇文章主要介紹了手機(jī)移動(dòng)端實(shí)現(xiàn) jquery和HTML5 Canvas的幸運(yùn)大獎(jiǎng)盤(pán)特效的相關(guān)資料,這里附有實(shí)現(xiàn)代碼及實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-12-12
jquery垂直公告滾動(dòng)實(shí)現(xiàn)代碼
公告滾動(dòng)想必大家都有見(jiàn)到過(guò)吧,實(shí)現(xiàn)方法也有很多,下面為大家介紹使用jquery實(shí)現(xiàn)垂直公告滾動(dòng),感興趣的朋友不要錯(cuò)過(guò)2013-12-12
jQuery Validate讓普通按鈕觸發(fā)表單驗(yàn)證的方法
一般的表單校驗(yàn)都是直接注冊(cè)在頁(yè)面上的匿名函數(shù),導(dǎo)致只能通過(guò)固定的提交方式觸發(fā)表單校驗(yàn),如果想自定義一個(gè)按鈕觸發(fā)表單校驗(yàn)如何實(shí)現(xiàn)呢,下面通過(guò)本文給大家詳細(xì)介紹2016-12-12
jquery京東商城雙11焦點(diǎn)圖多圖廣告特效代碼分享
這篇文章主要介紹了jquery京東商城雙11焦點(diǎn)圖多圖廣告特效,一個(gè)精致的焦點(diǎn)圖會(huì)吸引用戶的注意力,讓用戶產(chǎn)生瀏覽網(wǎng)站的興趣至關(guān)重要,現(xiàn)在小編推薦給大家一款特別棒的焦點(diǎn)圖,感興趣的小伙伴可以參考下。2015-09-09
jquery使用jquery.zclip插件復(fù)制對(duì)象的實(shí)例教程
這篇文章主要介紹了jquery使用jquery.zclip插件復(fù)制對(duì)象的實(shí)例教程,當(dāng)然也可以復(fù)制輸入框input、textarea等內(nèi)容,下面看代碼2013-12-12
jquery實(shí)現(xiàn)簡(jiǎn)單易懂的圖片展示小例子
圖片展示想必大家都見(jiàn)到過(guò)吧,下面有個(gè)不錯(cuò)的例子,通俗易懂,使用jquery實(shí)現(xiàn)的,感興趣的朋友不要錯(cuò)過(guò)2013-11-11
jQuery實(shí)現(xiàn)全部購(gòu)物車功能實(shí)例
本文詳細(xì)講解了jQuery實(shí)現(xiàn)全部購(gòu)物車功能,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11

