限制contenteditable可编辑容器内容的长度,最大长度限制
npm install maxlength
针对contenteditable实现的输入框,限制其输入长度。
在线例子
js
maxlength({
dom: '', // 必填属性,原生dom
maxLength: 0, // 必填属性,如果没填,限制不生效
})
`
安装和使用
$3
`js
`
$3
安装maxlength
`base
npm i maxlength --save
`
$3
引入包,使用包
`js
import maxLength from 'maxlength'
// 获取设置了contenteditable属性的dom
const editor = document.getElementById('editor')
maxLength({
dom: editor,
maxLength: 10
}
`
html结构
`html
max-length
contenteditable可编辑容器的内容最大长度限制
``