3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getAttributes.js 838 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-12 16:04 . chore: 调整单测代码
import isArray from './utils/types/isArray'
import isElement from './isElement'
import getAttribute from './getAttribute'
/**
* 获取 DOM 元素的单个或多个 HTML 属性值(键/值对象)
* ========================================================================
* @method getAttributes
* @param {HTMLElement} el
* @param {Array} [props]
* @return {Object|Boolean}
*/
const getAttributes = (el, props = []) => {
const attrs = {}
let keys = [...props]
if (!isElement(el)) {
return false
}
if (!isArray(keys) || keys.length < 1) {
keys = el.getAttributeNames()
}
keys.forEach((key) => {
const value = getAttribute(el, key)
/* istanbul ignore else */
if (value) {
attrs[key] = value
}
})
return attrs
}
export default getAttributes
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助