1.
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml" > 5 <head> 6 <title>标题页</title> 7 <script language="javascript"> 8 function getAddress(e) 9 { 10 var t=e.offsetTop; 11 var l=e.offsetLeft; 12 while(e=e.offsetParent) 13 { 14 t+=e.offsetTop; //获取X坐标 15 l+=e.offsetLeft; //获取Y坐标 16 } 17 alert("x坐标="+t+" y坐标为="+l); 18 } 19 </script> 20 </head> 21 <body> 22 <input id="Button1" type="button" value="坐标" onclick="getAddress(this)" /> 23 </body> 24 </html>