Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为我的项目制作一个提示弹出窗口。当用户单击“打开提示”按钮时,提示窗口将显示在某些元素旁边。
我的问题是我从 ajax 创建的元素也需要在它们旁边显示提示窗口,如果用户在调用 ajax 之前单击按钮,这些元素将不会显示提示窗口,因为它们不存在。对这个问题有什么建议吗?非常感谢。
您可以使用on()充当delegate动态元素来绑定事件。下面,我将事件注册到现在或以后存在于上的click任何事件。documentclasstips
on()
delegate
click
document
class
tips
$(document).on('click','.tips', function(){ // show tips; });
我通过调用一个函数来解决此类问题dommods()。调用时,它会将我想要的任何效果应用于文档,例如工具提示。我只是在每次更改 DOM 后调用它,这样就解决了问题。
dommods()