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/> 您正在掩盖的元素。 还有
接受其他值为
此处记录。 。 。 .
示例
要看到代码运行的例子, 请遵循这些步骤 :
- 切开回转机,
git clone [email protected]:text-mask/text-mask.git cd text-masknpm installnpm run vanilla:dev- 打开 http://localhost:3:00 (英语)
示例的代码在 vanilla/example。 。 。 .
捐款
我们想做点贡献! 检查出来 此文档 要开始.