如何为来自服务器的元素添加事件监听器?
如何使用addEventListener(window.onload)添加点击事件 当相关标签生成时 服务器(通过 xmphttp 请求,不少于)?
谢谢!
How do I add a click event using addEventListener (window.onload)
when the tags in question are being generated from
the server (via an xmphttp request, no less)?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试处理父元素的事件,这些事件在 DOM 加载时可用,然后获取与事件相关的元素。
You can try to handle events for parent elements, which are available as DOM loaded, then get element related to event.
谢谢大家。
我通过将以下代码添加到 XMLHTTP 请求的“成功时”事件解决了这个问题,该请求使用来自服务器的元素填充 DOM。这对我有用。
乔希,你让我的头脑朝着正确的方向发展(尽管很高兴看到代码插图),所以我将你的回复标记为答案。
Thanks all.
I solved this by adding the below code to the "on success" event of the XMLHTTP request that populated the DOM with the elements coming from the server. That worked for me.
Josh, you got my head moving in the right direction (although it would have been nice to see a code illustration) so I marked your response as the answer.
您必须在元素插入 DOM 后应用事件处理程序
You have to apply the event hanlders after the elements have been inserted into the DOM