Javascript 显示展开/折叠截面的偏移坐标

Javascript 显示展开/折叠截面的偏移坐标,javascript,jquery,html,sections,Javascript,Jquery,Html,Sections,我的网页中有一个展开/折叠部分。展开/折叠是使用部分而不是div/table完成的。我的代码是: <section id="examples"> <text id = "ui-examples"> <p class="the-data">Of course you can add other text before, after, and around the elements described in the previous sec

我的网页中有一个
展开/折叠
部分。展开/折叠是使用
部分
而不是
div/table
完成的。我的代码是:

<section id="examples">
    <text id = "ui-examples">
        <p class="the-data">Of course you can add other text before, after, and around the elements described in the previous section.</p>
    </text>
</section>

当然,您可以在上一节中描述的元素之前、之后和周围添加其他文本

在加载页面时,会出现许多
数据的实例
,因此
ui示例
会加载不同的ID和相应的
数据
。如何获取这些不同的
文本ID
,以计算每个
文本的
偏移量
坐标


编辑格式

我会这样做:

HTML文件

<section class="examples">
    <text class="ui-examples">
        <p class="the-data">Of course you can add other text before, after, and around the elements described in the previous section.</p>
    </text>
</section>
这首先是等待文档准备就绪,一旦文档准备就绪,它就会在每个循环中循环,循环中有一个类“example”,我们使用
find
jQuery函数搜索与选择器匹配的当前div的所有子项(在本例中是
.example
)的一个实例。因此,通过使用
。数据
将找到您要查找的段落标记


然后,您可以使用
offset()
获取坐标。

请注意,如果有许多“示例”实例作为ID,那么您应该改用类。ID是一个HTML元素的唯一标识符。虽然可以,但在一个页面上有多个ID并不是一个好的做法。您应该改用类。
$(document).ready(function() {
    $('.examples').each(function() {
        var theData = $(this).find('.the-data');
        console.log(theData.offset().left);
        console.log(theData.offset().top);
    });
});