开发者

Jquery: Using live with plugins

开发者 https://www.devze.com 2023-02-11 11:20 出处:网络
Having a table with class .data, I want to apply setMask, usual way is: $(\".data tbody tr input:text\").setMask();

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.

0

精彩评论

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