javascript - How can I apply a dynamic mask in an dynamic form? -
i have problem dynamic form. input is:
<input type="text" class="form-control" placeholder="ex: (xx)-xxxx-xxxx" name="phone[]" id="phone">
this input have mask
$('#phone').mask('(00)-0000-00000');
everything works fine, when add together button append new input after first .mask filter doesn't work new . how can apply dynamic mask in dynamic form?
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 have add together dynamically this. untested code thought remains 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]); )};
here illustration of how execute js appending dynamically in htmls - enter link description here way can append code snippet dynamically created htmls. hope helps
javascript jquery dynamic
No comments:
Post a Comment