jquery访问通过ajax调用加载的内容
我正在尝试编写一个 jquery 插件,当我单击图像时会弹出警报消息。这些图像是通过 load() 方法加载的。是否可以在文档准备好时加载插件,并且插件可以访问加载的内容?我不想使用回调函数,我只想将插件包含在 html 页面中,然后插件执行它的操作。
i'm trying to write a jquery plugin that when i click on a image to pop an alert message. Those images are loaded via load() method. Is there possible to load the plugin on document ready and the plugin to have acces to the loaded content? i don't want to use a callback function, i just want to include the plugin in the html page and then the plugin do it's thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确的话,您可能想使用 jQuery.live 方法 绑定 onClick处理符合查询的所有当前和未来图像。例如,您可以说
然后每个具有“alerting”类的图像将始终有一个单击处理程序,即使是运行上述代码时不存在的图像。
If I understand you correctly, you probably want to use the jQuery.live method to bind an onClick handler to all present AND future images that conform to a query. For example, you can say
And then every image with the "alerting" class will always have a click handler, even images that didn't exist when you ran the above code.
尝试使用 实时事件 捕获所有 img 元素的点击事件(无论何时添加) 。
Try using live events to catch the click event for all img elements, whenever they were added.