是否可以通过 DOM 直接使用标题轴属性检索 td 的轴标题?

发布于 2025-01-07 02:04:50 字数 2519 浏览 0 评论 0原文

我最近发现,我可以使用 td 上的 headers 属性和 axisth 上的 code> 属性。示例:

<table>
    <caption>Country Toy Codes</caption>
    <thead>
        <tr>
            <th scope="col row"></th>
            <th scope="col" id="us" axis="country">US</th>
            <th scope="col" id="ca" axis="country">CA</th>
            <th scope="col" id="uk" axis="country">UK</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row" id="robots" axis="toys">Robots</th>
            <td headers="us robots">ABC</td>
            <td headers="ca robots">DEF</td>
            <td headers="uk robots">GHI</td>
        </tr>
        <tr>
            <th scope="row" id="dolls" axis="toys">Dolls</th>
            <td headers="us dolls">JKL</td>
            <td headers="ca dolls">MNO</td>
            <td headers="uk dolls">PQR</td>
        </tr>
        <tr>
            <th scope="row" id="slinkys" axis="toys">Slinkys</th>
            <td headers="us slinkys">STU</td>
            <td headers="ca slinkys">VWX</td>
            <td headers="uk slinkys">YZ1</td>
        </tr>
        <tr>
            <th scope="row" id="legos" axis="toys">Legos</th>
            <td headers="us legos">AB1</td>
            <td headers="ca legos">CD1</td>
            <td headers="uk legos">EF1</td>
        </tr>
    </tbody>
</table>

这对于非视觉浏览器有明显的好处,但我认为它对于 javascript 和 css 也很有用。唯一的问题是,无论是在选择之后还是出于选择目的,我都没有看到直接访问单元格标题 id 的轴类型的方法。

理想情况下,我想做以下任一操作(前面的粗略伪代码):

  Selector:
      td['axis=toys']  // Would select all td's with a header id that resolves to a header having axis value "toys"

  Getter:
      $('td').axisValue("toys") // would return the value, if applicable, of header id of header value with axis value of toys.

对于 getter,我可以每次循环遍历每个标头,并从 DOM 中的 id 找到元素,然后找到轴值,但如果有是一种更直接地执行此操作的方法,我确信浏览器也对其进行了更优化。

对于选择器,我能想到的最接近的(在js中)是获取给定的轴值,找到使用该轴值的所有id,然后用逗号分隔每个选项以获取所有选项,例如

[headers~=us], [headers~=ca], [headers~=uk]

Does Anybody Know if header id's axis name 可以通过方法使用还是直接在 td 元素上使用?

Something I've recently discovered is that I can set a table cell to have multiple axises using a combination of the headers property on the td and the axis property on any related th. Example:

<table>
    <caption>Country Toy Codes</caption>
    <thead>
        <tr>
            <th scope="col row"></th>
            <th scope="col" id="us" axis="country">US</th>
            <th scope="col" id="ca" axis="country">CA</th>
            <th scope="col" id="uk" axis="country">UK</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row" id="robots" axis="toys">Robots</th>
            <td headers="us robots">ABC</td>
            <td headers="ca robots">DEF</td>
            <td headers="uk robots">GHI</td>
        </tr>
        <tr>
            <th scope="row" id="dolls" axis="toys">Dolls</th>
            <td headers="us dolls">JKL</td>
            <td headers="ca dolls">MNO</td>
            <td headers="uk dolls">PQR</td>
        </tr>
        <tr>
            <th scope="row" id="slinkys" axis="toys">Slinkys</th>
            <td headers="us slinkys">STU</td>
            <td headers="ca slinkys">VWX</td>
            <td headers="uk slinkys">YZ1</td>
        </tr>
        <tr>
            <th scope="row" id="legos" axis="toys">Legos</th>
            <td headers="us legos">AB1</td>
            <td headers="ca legos">CD1</td>
            <td headers="uk legos">EF1</td>
        </tr>
    </tbody>
</table>

This has clear benefits for non-visual browsers, but I was thinking it could also be useful for javascript and css. The only problem is that I'm not seeing a way to directly access the axis type of the header id of the cell, either after selecting or for selection purpose.

Ideally, I would like to do either of the following (rough pseduo-code ahead):

  Selector:
      td['axis=toys']  // Would select all td's with a header id that resolves to a header having axis value "toys"

  Getter:
      $('td').axisValue("toys") // would return the value, if applicable, of header id of header value with axis value of toys.

For the getter, I could loop through each header each time and find the element from the id in the DOM and then the axis value, but if there is a way to do this more directly, I'm sure it's also more optimized by the browser.

For the selector, the closest I can think of (in js) is to take the given axis value, find all ids using that axis value and then comma-separate each option to grab them all, such as

[headers~=us], [headers~=ca], [headers~=uk]

Does anyone know if header id's axis name is available either via a method or directly on the td element?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文