代码拉取完成,页面将自动刷新
import isElement from './isElement'
import getAttribute from './getAttribute'
import removeAttribute from './removeAttribute'
import setAttribute from './setAttribute'
import getStyle from './getStyle'
import { READONLY_INPUT_TYPES } from './utils/enum'
/**
* 启用或者取消 DOM 元素的只读模式
* ========================================================================
* @method readonly
* @since 1.2.0
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly
* @param el
* @return {boolean}
*/
const readonly = (el) => {
const TAGS = ['input', 'textarea']
let tagName
let type
if (!isElement(el)) {
return false
}
tagName = el.tagName.toLowerCase()
if (TAGS.indexOf(tagName) === -1) {
return false
}
if (tagName === 'input') {
type = getAttribute(el, 'type').toLowerCase()
if (
READONLY_INPUT_TYPES.indexOf(type) === -1 ||
getStyle(el, 'display') === 'hidden'
) {
return false
}
}
if (getAttribute(el, 'readonly')) {
removeAttribute(el, 'readonly')
} else {
setAttribute(el, 'readonly', true)
}
}
export default readonly
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。