[英]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.