HTML 代码: pHello/pp2nd Paragraph/p jQuery 代码: var p = $(p:first); var position = p.position(); $(p:last).html( left: + position.left + , top: + position.top );
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN html xmlns= head meta http-equiv=Content-Type content=text/html; charset=gb2312 / title无标题文档/title style type=text/css .tip /style script type=text/javascript var flag = true; function getMouseXY(e){ var posx=0,posy=0; if(e==null) e=window.event; if(e.pageX || e.pageY){ posx=e.pageX; posy=e.pageY; } else if(e.clientX || e.clientY){ if(document.documentElement.scrollTop){ posx=e.clientX+document.documentElement.scrollLeft; posy=e.clientY+document.documentElement.scrollTop; } else{ posx=e.clientX+document.body.scrollLeft; posy=e.clientY+document.body.scrollTop; } } return { X : posx, Y : posy } }
function getDiv(){ return document.createElement(div); }
function g(id)
function showTip(){ if(!flag) return; var domE = g(tip); if(!domE){ domE = getDiv(); domE.setAttribute(id,tip); document.body.appendChild(domE); domE.className = tip; } var m = getMouseXY(); with(domE.style){ top = (m.Y+20)+px; left = (m.X)+px; } }