JQuery用户名校验的具体实现

JQuery用户名校验的具体实现

本实例为大家分享了JQuery用户名校验功能,分享给大家供大家参考,具体内容如下

$(document).ready(function(){}):定义页面装载完成时,需要执行的方法。

$()获得页面指定的节点,参数是某种CSS的选择器。返回的是一个JQuery对象,可在其上执行JQuery方法。

val()方法可以获得节点的value属性值

html()设定某个节点中的html内容

click()相应鼠标点击事件

keyup()相应键盘弹起事件

$.get()可以和服务器进行get方式的交互,注册的callback方法会在数据回来的时候被调用,此方法会接收到代表服务器端返回数据的一个纯文本的参数

addClass()removeClass()给某个节点增加或删除一个class

解决中文乱码问题:发送给服务器端的数据在js中做两次encodeURI,然后在服务器端的代码中按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;

/**
* 用户名验证Servlet
* @author Ying-er
* @time 2010-4-25下午08:02:08
* @version 1.0
*/
public class UserVerify extends HttpServlet {

/**
* Processes requests for both HTTP

© 版权声明

相关文章

暂无评论

none
暂无评论...