* @description 异步选择器 * @param selector * @returns
(selector, parent = document, timeout)
| 1944 | * @returns |
| 1945 | */ |
| 1946 | function $_(selector, parent = document, timeout) { |
| 1947 | return new Promise((resolve) => { |
| 1948 | const timer = setInterval(() => { |
| 1949 | const selectors = Array.from(parent.querySelectorAll(selector)); |
| 1950 | // 存在元素 |
| 1951 | if (selectors.length) { |
| 1952 | clearInterval(timer); |
| 1953 | resolve(selectors); |
| 1954 | } |
| 1955 | }, 10); |
| 1956 | // 超时 |
| 1957 | if (timeout) { |
| 1958 | setTimeout(() => { |
| 1959 | clearInterval(timer); |
| 1960 | resolve([]); |
| 1961 | }, timeout); |
| 1962 | } |
| 1963 | }); |
| 1964 | } |
| 1965 | /** |
| 1966 | * @description 创建元素块 |
| 1967 | * @param eles |
no outgoing calls
no test coverage detected