[英]Jquery: Using live with plugins
Having a table with class .data, I want to apply setMask, usual way is: 有一个带有类.data的表,我想应用setMask,通常的方法是:
$(".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 like to find a solution to this. 我想找到一个解决方案。
Use liveQuery
plugin. 使用liveQuery
插件。 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
. 您只能将现有事件绑定到live
和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. 在我的一生中,我找不到完整的列表(已经尝试了很多次),但是没有ready
load
的内容:也就是说,无法绑定正在加载的元素,至少没有跨浏览器的方式。 If you only care about non-IE, then I believe DomNodeInserted
will work as an event. 如果您只关心非IE,那么我相信DomNodeInserted
将作为一个事件工作。
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: 因此,当您插入表格行时,只需按照以下方式对其运行setMask:
$tr = $(".data tbody").insertTableRow(); //Pretend function returns tr object
$tr.setMask();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.