简体   繁体   English

JS中用于输入掩码插件的事件处理程序

[英]Event handler in JS for input mask plugin

I am using Jquery input mask plugin to handle timestamps. 我正在使用Jquery输入掩码插件来处理时间戳。 Writing the following code appends the plugin to all the relevant text boxes. 编写以下代码会将插件附加到所有相关的文本框中。

$('input[name="start-time"]').inputmask(
   "hh:mm:ss", {
       placeholder: "HH:MM:SS",
       insertMode: false,
       showMaskOnHover: false,
       hourFormat: "24"
   }
);

However, In my case I have dynamically generated text boxes as well. 但是,就我而言,我也动态生成了文本框。 How do I get the input mask to be applied to those? 我如何获得要应用于这些输入的掩码? I went through all the list of event handlers, and I wasn't able to find one which has on the creation of a new field, fire an event handler. 我遍历了所有事件处理程序列表,但找不到一个创建新字段的事件处理程序。

When the input text is added dynamically, you can as well call the inputmask method for that element. 动态添加输入文本后,还可以调用该元素的inputmask方法。 Another option would be to get notified when the element is added then call inputmask on the element. 另一种选择是在添加元素时获得通知,然后在元素上调用inputmask。

$("<ancestor-element-selector>").on("DOMNodeInserted", 'input[name="start-time"]', function(){
    //call inputmask on the new element.    
    //$(this).inputmask(/*params...*/);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM