让ajax中实现提示框

tooTip.html:


  

 
  Ajax Tooltip
  
 
 
  

Ajax Tooltip Example


  

Golf Courses


  
    
      
      
      
      
        
  
Augusta National
Pinehurst No. 2
St. Andrews Links
Baltusrol Golf Club

  
  
 

ToolTipServlet.java:
  
/*
* ToolTipServlet.java
*
* Created on June 30, 2005, 8:29 PM
*/
  
package ajaxbook.chap4;
  
import java.io.*;
import java.util.HashMap;
import java.util.Map;
  
import javax.servlet.*;
import javax.servlet.http.*;
  
/**
*
* @author nate
* @version
*/
public class ToolTipServlet extends HttpServlet {
  
  private Map courses = new HashMap();
  
  public void init(ServletConfig config) throws ServletException {
    CourseData augusta = new CourseData(72, 7290);
    CourseData pinehurst = new CourseData(70, 7214);
    CourseData standrews = new CourseData(72, 6566);
    CourseData baltusrol = new CourseData(70, 7392);
    courses.put(new Integer(1), augusta);
    courses.put(new Integer(2), pinehurst);
    courses.put(new Integer(3), standrews);
    courses.put(new Integer(4), baltusrol);
  }
  
  /** Handles the HTTP GET method.
   * @param request servlet request
   * @param response servlet response
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    Integer key = Integer.valueOf(request.getParameter("key"));
    CourseData data = (CourseData) courses.get(key);
    
    PrintWriter out = response.getWriter();
  
    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");
  
    out.println("");
    out.println("" + data.getPar() + "");
    out.println("" + data.getLength() + "");
    out.println("
");
    out.close();
  }
  
  /** Handles the HTTP POST method.
   * @param request servlet request
   * @param response servlet response
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    doGet(request, response);
  }
    
  /** Returns a short description of the servlet.
   */
  public String getServletInfo() {
    return "Short description";
  }
  
  private class CourseData {
    private int par;
    private int length;
    
    public CourseData(int par, int length) {
      this.par = par;
      this.length = length;
    }
    
    public int getPar() {
      return this.par;
    }
    
    public int getLength() {
      return this.length;
    }
  }
}

 

  注释:提示框的位置是计算距离顶部的距离

  eg:

  假设 obj 为某个 HTML 控件。

  obj.offsetTop 指 obj 距离上方或上层控件的位置,整型,单位像素。

  obj.offsetLeft 指 obj 距离左方或上层控件的位置,整型,单位像素。

  obj.offsetWidth 指 obj 控件自身的宽度,整型,单位像素。

  obj.offsetHeight 指 obj 控件自身的高度,整型,单位像素。

你可能感兴趣的:(Ajax,Ajax,Servlet,JavaScript,HTML,Cache)