在document.ready之后将jQuery附加到按钮 [英] Attaching jQuery to buttons after document.ready
问题描述
我正在根据以下文章编写一些代码:
I'm writing some code based on the following article:
我想做的是在每行上都有按钮,以在按钮所在的行下方添加一个新行.
What I would like to do is to have buttons on each row to add a new row below the row the button is on.
这对于第一行工作正常,因为document.ready中有代码,可以将jQuery函数附加到按钮上.
This works OK for the first row, because there is code in document.ready to attach a jQuery function to the button.
但是,第二行中的按钮是动态添加的-如何将相同的功能附加到此动态添加的按钮上?
However, the button in the second row is added dynamically - how do I attach the same function to this dynamically added button?
谢谢.
马特.
推荐答案
将live()用于动态添加的对象
use live() for dynamically added objects
代替
$('.button').click(function(){});
使用
$('.button').live('click',function(){});
Binds a handler to an event (like click) for all current - and
未来-匹配的元素.也可以绑定自定义事件.
future - matched element. Can also bind custom events.
这篇关于在document.ready之后将jQuery附加到按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!