maskedinput是一个简单但可完全配置的jQuery输入掩码插件,允许用户以特定格式在固定位置键入字符。非常适合日期/IP地址/货币输入字段。
1.在页面上包含必要的JavaScript库。
<script src="/path/to/cdn/jquery.slim.min.js"></script> <script src="/path/to/dist/jquery.maskedinput.umd.min.js"></script>
2.创建一个新的MaskedInput对象,并按如下方式设置数据格式:
var dateMask = new MaskedInput({ format: 'dd/MM/yyyy hh:mm tt', // additional patterns to recognize the format patterns: {} });
3.将日期掩码附加到给定的输入。
dateMask.$el.appendTo('#date-field-cell');
4.设置每个字段的选项:
dateMask .fieldOption('hours_12', 'required', false) .fieldOption('minutes', 'required', false) .fieldOption('ampm', 'required', false) .resize();
5.API方法。
dateMask // Get an internal field element by index or by name. .field(index) // Get/set a field's configuration option .fieldOption(name, newValue) // Get/set an internal field's value by index or by name. .fieldValue(index, newValue) // Get/set a configuration option .option(name, newValue) // Call if something has drastically changed and the control needs to be regenerated. // Only applicable when you've manually changed a field's type. .render() // Update the size of the field's content. // This can't be called when the control is not on the DOM yet. If you don't want the field to be dynamically sized, you can skip calling this. .resize() // A synonym for value .val(newValue?) // Get/set the full value .value(newValue?)
7.零件类型参数:
/** * @typedef {String} MaskedInput~PartType * @name MaskedInput~PartType * @enum {String} */ var PartType = { /** @const */ NUMBER: 'number', /** @const */ TEXT: 'text', /** @const */ LABEL: 'label' };
8.屏蔽输入部件参数:
9.屏蔽输入模式参数:
10.屏蔽输入选项:
2022-12-09
2022-01-11
2022-01-10
2021-04-26
2021-04-21
2021-01-03
2018-12-07
2017-05-09
2017-05-04
2017-01-15