For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/lynx-api/lynx/lynx-create-selector-query.md.
Lynx
  • 简体中文
  • lynx: createSelectorQuery() static method

    创建一个以页面根节点为根的 SelectorQuery

    语法

    createSelectorQuery(): SelectorQuery;

    参数

    无。

    返回值

    以页面根节点为根的 SelectorQuery 对象。

    示例

    获取指定 text 节点的位置和大小:

    import { useEffect } from '@lynx-js/react';
    
    function App() {
      useEffect(() => {
        lynx
          .createSelectorQuery() // 创建 SelectorQuery
          .select('#my-id') // 指定目标节点的选择器
          .invoke({
            // 指定对目标节点的操作
            method: 'boundingClientRect',
            success: function (res) {
              console.log(res);
            },
            fail: function (res) {
              console.log(res.code, res.data);
            },
          })
          .exec(); // 执行查询
      }, []);
    
      return (
        <view>
          <text id="my-id">Hello, ReactLynx</text>
        </view>
      );
    }

    兼容性

    LCD tables only load in the browser

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。