jQuery use .live with jquery-keyfilter plugin
I am using jquery-keyfilter plugin to mask textbox inputs. However the textboxes are added to the page dynamically and I cannot figure out how to apply the key filter to the开发者_高级运维m.
I have tried
$('#myelement').live('keyfilter', myFunction );
Also
$('#myelement').live('keyfilter', /regex/);
Kai: comment helps, but it seems my problem is still not solved
I want a keyfilter like this
(/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/);
that will only accept currency/money values but it seems like jquery-keyfilter does not work with this regex. Is this something I am doing wrong or should I look at using another plugin or just code it myself?
"keyfilter" is not an event and you can NOT use live().
According to API of the plugin, it should be
$('#myelement').keyfilter(function(c) { return c != 'a'; });
$('#myelement').keyfilter(/[\dA-F]/);
Below solution works for non-first character
$("#myelement").live("keypress", function(){ $(this).keyfilter((/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/); });
Below solution works for input field already clicked
$("#myelement").live("click", function(){ $(this).keyfilter((/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/); });
精彩评论