$(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>

          }

          posted on 2010-04-25 20:10 Ying-er 閱讀(963) 評(píng)論(2)  編輯  收藏 所屬分類: JQuery

          評(píng)論:
          # re: 使用JQuery進(jìn)行用戶名校驗(yàn) 2010-05-14 12:38 | 何楊
          建議使用Apache的StringUtils,它漸漸已經(jīng)成為字符串處理的通用包了。  回復(fù)  更多評(píng)論
            
          # re: 使用JQuery進(jìn)行用戶名校驗(yàn) 2010-05-15 11:04 | Ying-er
          @何楊
          恩那!~
          技術(shù)更新真快,我都o(jì)ut了。  回復(fù)  更多評(píng)論
            

          填坑女俠  

          <2010年5月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          友情鏈接

          各人常用鏈接

          搜索

          •  

          積分與排名

          • 積分 - 194860
          • 排名 - 297

          最新評(píng)論

          閱讀排行榜

          主站蜘蛛池模板: 孟州市| 绍兴县| 兰州市| 屏东市| 维西| 新兴县| 永济市| 莆田市| 道孚县| 天镇县| 荆州市| 古丈县| 广南县| 门源| 平潭县| 大丰市| 兖州市| 邵东县| 扶沟县| 罗平县| 德阳市| 抚州市| 木兰县| 甘德县| 慈利县| 开原市| 大化| 博罗县| 遵化市| 色达县| 星子县| 昂仁县| 山东省| 万山特区| 辰溪县| 武功县| 东丽区| 新昌县| 金溪县| 天门市| 宣威市|