position()

本页内容
上一节: Html_outerwidth 下一节: Html_prepend

jQuery position() 方法

jQuery HTML/CSS 方法

返回 <p> 元素的 top 和 left 位置:


示例

$("button").click(function(){
    x=$("p").position();
    alert("Top: " + x.top + " Left: " + x.left);
});

定义和用法

position() 方法返回第一个匹配元素的位置(相对于它的父元素)。

该方法返回一个带有两个属性(以像素为单位的 top 和 left 位置)的对象。

语法

$(selector).position()

更多实例

返回元素相对于它的父元素的位置 如何获取 <p> 元素在 <div> 元素内部的位置。

jQuery HTML/CSS 方法

上一节: Html_outerwidth 下一节: Html_prepend
此页面最后编辑于2022年8月19日 (星期五) 11:44。