如何以动态形式应用动态蒙版? [英] How can I apply a dynamic mask in an dynamic form?
问题描述
我的动态表单有问题。此输入为:
I have a problem with my dynamic form. This input is:
<input type="text" class="form-control" placeholder="EX: (XX)-XXXX-XXXX" name="phone[]" id="phone">
此输入有掩码
$('#phone').mask('(00)-0000-00000');
一切正常,但是当我添加一个在第一个.mask之后追加新输入的按钮时过滤器不适用于新的。
如何以动态形式应用动态掩码?
Everything works fine, but when I add a button who append a new input after the first the .mask filter doesn't work to the new . How can I apply a dynamic mask in an dynamic form?
.append函数是:
The .append function is:
$('#plusPhone').click(function(){
$('#appendPhone').append("<div class=\"row\"><div class=\"col-md-6\"><div class=\"form-group\"><label class=\"control-label col-md-3\">Phone</label><div class=\"col-md-9\"><input type=\"text\" class=\"form-control\" placeholder=\"EX: (XX)-XXXX-XXXX\" name=\"phone[]\" id=\"phone\"></div></div></div></div>"); });
推荐答案
您必须像这样动态添加它。
这是一个未经测试的代码,但这个想法保持不变。
You will have to add it dynamically just like this. This is an untested code but the idea remains the same.
$('#plusPhone').click(function(){
$('#appendPhone').append("<div class=\"row\"><div class=\"col-md-6\"><div class=\"form-group\"><label class=\"control-label col-md-3\">Phone</label><div class=\"col-md-9\"><input type=\"text\" class=\"form-control\" placeholder=\"EX: (XX)-XXXX-XXXX\" name=\"phone[]\" id=\"phone\"></div></div></div></div>");
var code = "<script>$('#telefone').mask('(00)-0000-00000');</scr"+"ipt>";
$('#appendPhone').append($(code)[0]);
)};
以下是如何通过在htmls中动态附加js来执行js的示例 - 在此处输入链接说明
这样您就可以将代码段附加到动态创建的htmls中。希望它有所帮助
Here is an example of how to execute js by appending it dynamically in htmls - enter link description here This way you can append the code snippet to dynamically created htmls. Hope it helps
这篇关于如何以动态形式应用动态蒙版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!