简体   繁体   English

如何将隐藏的日期输入放入动态创建的文本字段中?

[英]How can I put masked date input in a dynamically created text field?

I am using jquery date input plugin from here 我正在从这里使用jQuery日期输入插件

I call the function inside the html page like this 我像这样在html页面内调用函数

jQuery(function($){
   $("#date").mask("99/99/9999");

});

It works fine in every fields where we just have to specify the id of the element. 在每个我们只需指定元素ID的字段中,它都能正常工作。

I have a table which creates table rows of html elements dynamically, I want the date input plugin to apply date mask in the text box having mfd date. 我有一个可以动态创建html元素的表行,我希望日期输入插件在具有mfd日期的文本框中应用日期掩码。

Since the id keeps changing dynamically as the row length is being added one by one to the id to make the id unique. 由于随着行长被逐一添加到id中以使id唯一,因此id保持动态变化。

How can i use the masked date input inside the dom table ? 我该如何使用dom表中输入的隐藏日期?

You could do the work inside your insSpec function, where you have both the ID and the markup at your disposal. 您可以在insSpec函数中完成工作,在其中可以使用ID和标记。

Without using the ID: 不使用ID:

$(f).find('input[name^="mfd_date"]').mask('99/99/9999');

Using the ID: 使用ID:

$(f).find('#mfd_date'+rl).mask('99/99/9999');

And since that cell really only has one input, you only need to look for the input 由于该单元格实际上只有一个输入,因此您只需要查找输入

$(f).find('input').mask('99/99/9999');

Or you could emit an event after the new row has been created and attach the mask to the last row in the table always, or even pass the last row as data to the event listeners. 或者,您可以在创建新行之后发出事件,并将掩码始终附加到表的最后一行,甚至可以将最后一行作为数据传递给事件侦听器。

It is a good idea to use a permanent class. 使用永久类是一个好主意。 If you use ajax, maybe you need to use callback function to wait for a code loaded before you apply the mask. 如果使用ajax,则可能需要使用回调函数来等待代码加载,然后再应用掩码。 You can also use a bordering div or span tag around your input tag with the permanent id. 您还可以在带有永久ID的输入标签周围使用边框div或span标签。 If you have constant amount of input in form you can use 如果表格中的输入量恒定,则可以使用

$('table input[type=text]').eq(n)

,where n in eq(n) is item number in the sequence of inputs ,其中eq(n)中的n是输入序列中的项目编号

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

相关问题 如何从通过 Javascript function 动态创建的输入字段访问表单输入? - How can I access form input from an input field which was created dynamically via a Javascript function? 如何将 onchange() 事件附加到动态创建的输入文本字段中? - How do I attach an onchange() event into a dynamically created input text field? 如何将 1 个日期放入 2 个输入字段? - How can I put 1 date into 2 input fields? 我怎样才能把选择的选项 <select>从动态生成的表单到输入字段 - How can I put the selected option of a <select> from a dynamically generated form into an input field 如何使用 vanilla JavaScript 从动态创建的输入字段中获取数据? - How can I get data from dynamically created input field using vanilla JavaScript? 使用jQuery从动态创建的输入字段访问输入文本 - Access input text from dynamically created input field using jquery 如何仅在动态创建的字段上强制数字? - How can I force numbers only on a dynamically created field? 如何在动态创建的输入上绑定onchange事件? (没有jQuery) - How can I bind onchange event on dynamically created input ? (no jquery) 如何检测何时在输入字段中动态插入文本 - How do I detect when text is inserted dynamically in input field 如何屏蔽React.js的输入 - How can I masked input for React.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM