Ai
1 Star 0 Fork 12

NextZero/dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
has.js 935 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isString from './utils/types/isString'
import isFunction from './utils/types/isFunction'
import isCollection from './isCollection'
import isElement from './isElement'
import getEl from './getEl'
import filter from './filter'
/**
* 将匹配的元素集减少为具有与选择器或过滤函数匹配的子体的元素集。
* ========================================================================
* @method has
* @since 1.2.0
* @param {HTMLElement|NodeList} el
* @param {String|Function} selector
* @return {Array}
*/
const has = (el, selector) => {
if (
(!isElement(el) && !isCollection(el)) ||
(!isString(selector) && !isFunction(selector))
) {
return []
}
if (isElement(el)) {
/* istanbul ignore else */
if (isString(selector)) {
return [...getEl(selector, el, true)]
}
} else {
return filter(el, selector)
}
}
export default has
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/nextzero/dom.js.git
git@gitee.com:nextzero/dom.js.git
nextzero
dom.js
dom.js
main

搜索帮助