Having a table with class .data, I want to apply setMask, usual way is:
$(".data tbody tr input:text").setMask();
However I dynamically add new rows, thus a live function is needed for future created ones. I have tried this but failed:
$('.data tbody tr input:text').live('ready', function() {
$(this).setMask();
});
I would l开发者_JS百科ike to find a solution to this.
Use liveQuery
plugin. You can just bind with out any events.
$('.data tbody tr input:text').livequery(function() {
$(this).setMask();
});
You can only bind existing events to live
and bind
. For the life of me, I can't find a complete list (have tried many times), but ready
and load
are not on there: that is, there is no way to bind an element being loaded, at least not across browsers. If you only care about non-IE, then I believe DomNodeInserted
will work as an event.
Either way, you seem to control when you are inserting the table row, no? So when you insert the table row, then just run setMask on it, in this vein:
$tr = $(".data tbody").insertTableRow(); //Pretend function returns tr object
$tr.setMask();
Take a look at livequery plugin. It's a little different form $.live in that it can fire a function when a new matched element is added.
精彩评论