@formio/vanilla-text-mask

中文文档
5.1.1-formio.1发布于 2022/09/14UnlicenseCommonJS零依赖近 30 天下载 33.2万

JavaScript 函数使输入 HTML 元素接受掩码模式

中文使用文档
文档目录4 节
  1. 开始
  2. 文档
  3. 示例
  4. 捐款

Java 脚本输入罩

说明: 本模块不支持IE9.

开始

首先,安装它.

npm i vanilla-text-mask --save

然后,使用如下:

<script
  type="text/javascript"
  src="./node_modules/vanilla-text-mask/dist/vanillaTextMask.js"></script>
<script type="text/javascript">
  var phoneMask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]

  // Assuming you have an input element in your HTML with the class .myInput
  var myInput = document.querySelector('.myInput')

  var maskedInputController = vanillaTextMask.maskInput({
    inputElement: myInput,
    mask: phoneMask
  })
  
  // Calling `vanillaTextMask.maskInput` adds event listeners to the input element. 
  // If you need to remove those event listeners, you can call
  maskedInputController.destroy()
</script>

文档

从上面的代码中可以看到,您正在传递一个对象到 vanillaTextMask.maskInput(...)。 。 。 .

对象要 inputElement,这是 <input/> 您正在掩盖的元素。 还有 接受其他值为 此处记录。 。 。 .

示例

要看到代码运行的例子, 请遵循这些步骤 :

  1. 切开回转机, git clone [email protected]:text-mask/text-mask.git
  2. cd text-mask
  3. npm install
  4. npm run vanilla:dev
  5. 打开 http://localhost:3:00 (英语)

示例的代码在 vanilla/example。 。 。 .

捐款

我们想做点贡献! 检查出来 此文档 要开始.

版本与发布记录

@formio/vanilla-text-mask 共发布 2 个版本,首次发布于 2021/04/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.1.1-formio.1latest2022/09/144 年前
5.1.12021/04/205 年前

关于 @formio/vanilla-text-mask 的常见问题

@formio/vanilla-text-mask 是什么?

JavaScript 函数使输入 HTML 元素接受掩码模式

如何安装 @formio/vanilla-text-mask?

在项目目录运行 npm install @formio/vanilla-text-mask,或使用 pnpm add / yarn add / bun add。

@formio/vanilla-text-mask 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/formio__vanilla-text-mask 是否存在。

@formio/vanilla-text-mask 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@formio/vanilla-text-mask 可以商用吗?

@formio/vanilla-text-mask 使用 Unlicense 许可。作者将代码贡献到公共领域,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@formio/vanilla-text-mask 的下载量有多少?

根据 npm 官方下载统计,@formio/vanilla-text-mask 在 2026/10/16 – 2026/11/14 这 30 天内被下载 331,537 次,日均约 11,051 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formio/vanilla-text-mask 还在维护吗?

最新版本 5.1.1-formio.1 发布于 2022/09/14(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。