如果未找到所有元素,解决 jQuery 事件不会在 Internet Explorer 中触发的问题
我正在努力寻找更好的解决方案来解决这个问题。 我正在用 PHP 开发一个游戏,它有许多不同的内容页面。这些内容页面包含文档正文中的所有内容。我使用 jQuery 单击事件来调用 AJAX,它加载外部 PHP 并更新游戏。然而,在许多页面上,我使用 jQuery 选择器调用不同的元素。我希望只有一个 javascript 文件来管理所有 jQuery 事件,但根据 jQuery 网站上发布的评论;
*“IE 注意。如果您尝试在不存在的元素上分配实时事件处理程序,则任何其他实时事件处理程序都将不起作用,您也不会收到任何错误。”
http://api.jquery.com/live/
不幸的是,我的大部分玩家群我们还在使用IE 6-8。因此,在我的页脚文件中,我调用了许多不同的 JavaScript 文件。我希望有人能告诉我更好的解决方法,因为我的游戏有许多不同的页面,而且我不想在页脚中调用大量 JavaScript 文件。
或者,如果有什么办法我可以在 << 中包含一个 javascript 文件。身体>标签,这将是另一种解决方案(但根据我的研究,我认为这是不可能的)。
谢谢。
I'm trying to find a better solution for this problem.
I have a game that I'm developing in PHP and it has many different content pages. These content pages contain everything inside the document body. I'm using jQuery click events to call my AJAX which loads an external PHP and updates the game. However, on many pages I have different elements that I'm calling with my jQuery selector. I would like to have just one javascript file to manage all the jQuery events, but according the comment posted on the jQuery site;
*"Note for IE. If you try to assign a live event handler on an element that doesn't exist, then any other live event handlers will not work, you will receive no errors, either."
http://api.jquery.com/live/
Unfortunately, a large portion of my player-base us still using IE 6-8. Because of this, in my footer file, I'm calling many different JavaScript files. I was hoping that someone could tell me a better work around for this, since my game has many different pages, and I don't want to be calling a lot of JavaScript files in my footer.
Alternatively, if there was someway that I could include a javascript file from within the < body > tags, that would be another solution (but I from what I've researched I don't think this is possible).
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 delegate() 而不是 live()
delegate 与 live 类似,但您可以指定将在其中处理事件的根元素,而不是将事件传播回 document.root。
Try using delegate() instead of live()
delegate is similar to live but instead of propogating the event back to the document.root you can specify the root element in which the event will be handled.