3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
setStyle.js 686 Bytes
一键复制 编辑 原始数据 按行查看 历史
import toCamel from './utils/string/toCamel'
import isString from './utils/types/isString'
import isUndefined from './utils/types/isUndefined'
import isElement from './isElement'
/**
* 给 DOM 元素添加 CSS 样式
* ========================================================================
* @method setStyle
* @param {HTMLElement} el
* @param {String} attr
* @param {String} val
*/
const setStyle = (el, attr, val) => {
let prop
if (!isElement(el) || !isString(attr) || isUndefined(attr)) {
return false
}
prop = toCamel(attr)
if (prop === 'float') {
prop = 'cssFloat'
}
el.style[prop] = val
}
export default setStyle
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助