我有一个按钮,当您单击此按钮时,它会动态创建第二个按钮。我需要在动态创建的按钮(第二个按钮)上放置一个单击事件,我这样做了,但我的单击功能不起作用。
如何让我的点击函数与动态创建的元素一起使用?
最佳答案
您需要在创建第二个按钮后将单击事件绑定(bind)到它。或者使用 jQuery Live 或 Delegate 函数。
http://api.jquery.com/delegate/
Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.
如果您需要更多帮助,请发布一些代码。
关于javascript - 如何向在 jquery 中动态创建的元素添加操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7096631/