开发者

Apply a plugin's method to dynamically created elements?

开发者 https://www.devze.com 2023-03-13 21:59 出处:网络
I\'m using the jquery.maskedinput plugin to create a mas开发者_如何学Gok for a phone number field:

I'm using the jquery.maskedinput plugin to create a mas开发者_如何学Gok for a phone number field:

jQuery('input[type="tel"]').mask("(999) 999-9999");

Using a modification of Ryan Bates's nested form, I have a form where multiple phone numbers can be added dynamically via an "Add phone number" link. This link creates additional inputs, but the mask functionality is not applied. I am aware of the live() method in jQuery but am not sure if/how it can be used to apply the mask() method. Is there a way to apply this mask to dynamically created inputs?


To answer my own question... I used the jquery.livequery plugin to do the following:

$('input[type="tel"]').livequery(function() {
  $(this).mask("(999) 999-9?999");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消