3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getEl.js 745 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-12 16:04 . chore: 调整单测代码
import isBoolean from './utils/types/isBoolean'
import isElement from './isElement'
/**
* 返回与指定的选择器组匹配的文档中的 DOM 元素或者 DOM 元素列表。
* ========================================================================
* @method getEl
* @param {String} selector
* @param {HTMLElement|Boolean} [el]
* @param {Boolean} [multiple]
* @return {NodeListOf<*>|HTMLElement|*}
*/
const getEl = (selector, el, multiple = false) => {
const $el = isElement(el) ? el : document
let isMultiple = multiple
if (isBoolean(el)) {
isMultiple = el
}
if (isMultiple) {
return $el.querySelectorAll(selector)
}
return $el.querySelector(selector)
}
export default getEl
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助