Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是jquery
$('.li4').click(function(){ alert($('.img4').offset()); });
演示
但点击时它会发出警报.li4
.li4
.offset()返回一个对象 ( {left,top})。如果你想查看它,你可以使用JSON.stringify:
.offset()
{left,top}
JSON.stringify
alert(JSON.stringify($('.img4').offset()); // {"top":9,"left":171}
否则访问.left和.top属性:
.left
.top
var o = $('.img4').offset(); alert('x: ' o.left + '\ny: ' + o.top);
利用offset().left
offset().left
alert($('.img4').offset().left);