maxlength
TypeScript icon, indicating that this package has built-in type declarations

0.0.61 • Public • Published

max-length

gitHub tag badge gitHub release badge npm badge gitHub repo size badge jest badge badge


max-length

针对contenteditable实现的输入框,限制其输入长度。
在线例子

介绍

contenteditable可编辑容器的内容长度限制。一般利用contenteditable实现的可以输入区域,很难做到限制其输入的长度。这个库处理了英文输入、输入法输入、复制粘贴等情况,限制其内容的长度。

maxlength API

需要传入一个options配置项

maxlength(options)

maxlength({
  dom: '', // 必填属性,原生dom
  maxLength: 0, // 必填属性,如果没填,限制不生效
})

安装和使用

CDN

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/maxlength@latest/dist/index.min.js"></script>

<script>
  const editor = document.getElementById('editor')

  maxLength({
    dom: editor,
    maxLength: 10
  }
</script>

NPM

安装maxlength

npm i maxlength --save

使用

引入包,使用包

import maxLength from 'maxlength'
// 获取设置了contenteditable属性的dom
const editor = document.getElementById('editor')

maxLength({
  dom: editor,
  maxLength: 10
}

html结构

<div>
  <h1>max-length</h1>
  <hr />
  <p>contenteditable可编辑容器的内容最大长度限制</p>

  <div id="editor" contenteditable>
  </div>
</div>

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.6121latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.6121
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i maxlength

Weekly Downloads

21

Version

0.0.61

License

ISC

Unpacked Size

8.36 kB

Total Files

5

Last publish

Collaborators

  • gavin_gao