我想获得 div 的偏移值,但我只获得 HTML 文档的偏移量,即 0,0
这是测试代码:- HTML:-
<div id="result">Click an element.</div>
<div style="margin:auto; height:100px; width:134px; position:absolute; left: 193px; top: 53px;" id="name">JQuery</div>
脚本:-
$("*",document.body).mouseover(function (e) {
var offset = $(this).offset();
e.stopPropagation();
$("#result").text(this.tagName + " coords ( " + offset.left + ", " + offset.top + " )");
});