3 Star 56 Fork 13

Yaohaixiao/dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
byClass.js 819 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-12 16:04 . chore: 调整单测代码
import isString from './utils/types/isString'
import isElement from './isElement'
/**
* 返回与指定的类选择器组匹配的文档中的元素列表 (使用深度优先的先序遍历文档的节点)。
* 返回的对象是 NodeList 。
* ========================================================================
* @method byClass
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelectorAll
* @param {String} className
* @param {HTMLElement} [el]
* @return {NodeListOf<Element>|null}
*/
const byClass = (className, el) => {
let selector
let $el
if (!isString(className)) {
return null
}
selector = className.replace(/^./i, '')
$el = isElement(el) ? el : document
return $el.querySelectorAll(`.${selector}`)
}
export default byClass
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助

Cb406eda 1850385 E526c682 1850385