使用 jquery 时出现 IE 8 jquery 错误 + Rails ujs 驱动程序 +谷歌地图 v3.解决方法?
使用 jquery 1.4.4 和 1.5.1 进行测试,确认使用 jquery + Rails ujs 驱动程序(来自 github)+ google 地图 v3 时都存在问题
,单击地图标记会导致 IE 错误“失败”。当使用完整的、CDN 托管的 jquery v 1.5.1 时,IE 调试器指向第 2838 行(请注意,jquery.min.js 或版本 1.4.4 也会出现该问题)。
确认是ujs驱动触发了这个错误。删除驱动程序后,单击标记不会导致错误。
简单的实例可以在这里找到: http://avioing.com/maps/marker-simple.html< /a>.此页面是 Google 示例页面 http:// /code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html。我只添加了脚本调用来加载 jquery 和最新的 ujs 驱动程序。您应该能够通过单击地图标记来重现该错误。
示例页面在 FF 和 Chrome 中工作正常,错误仅发生在 IE 中,
另请参阅 http:// /avioing.com/maps/marker-simple_no_ujs.html 和 http://avioing.com/maps/marker-simple_no_marker.html,两者都不是表现出这个问题。
有人知道解决方法吗?
tested with jquery 1.4.4 and 1.5.1, confirmed problem with both
when using jquery + rails ujs driver (from github) + google maps v3, clicking on a map marker causes IE error "Fail". when using a full, CDN-hosted jquery v 1.5.1, IE debugger points at line 2838 (please note that the problem does also occur with jquery.min.js, or version 1.4.4).
confirmed that it is the ujs driver which triggers this error. when the driver is removed, clicking markers does not result in error.
simple live example is available here: http://avioing.com/maps/marker-simple.html. this page is an exact copy of google's example page http://code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html. i only added script calls to load jquery and the most recent ujs driver. you should be able to reproduce the error by clicking on the map marker.
the sample page works fine in FF and Chrome, and the error occurs only in IE
please also see http://avioing.com/maps/marker-simple_no_ujs.html and
http://avioing.com/maps/marker-simple_no_marker.html, neither of which exhibits this problem.
does anyone know of a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题让我想起了 IE 和 VML 的类似问题,如下所示: http://bugs.jquery .com/ticket/7071 其中,当 IE 遇到一个元素并且您尝试访问该元素的属性(jQuery 代码中的 elem.type)时,它会失败,并且不会满足对该元素的进一步访问尝试成功。
编辑:解决您的问题:
您引用的行是:jquery 1.5.1 中的 2838
您需要使用类似这样的内容来捕获错误:(破解 jquery 源)
警告:您可能会遇到更多类似问题的地方,因此测试好。
只是为了说明这一点,这不是最有效/最好的方法,但确实使您/我正在做什么来解决这个问题变得显而易见。
This issue reminds me of a similar issue with IE and VML as noted here: http://bugs.jquery.com/ticket/7071 where, when IE encounters an element and you try to access an attribute of that element (elem.type in the jQuery code), it fails and further access attempts to that element are not met with success.
EDIT: WORK AROUND FOR YOUR ISSUE:
The line cited by you is: 2838 in jquery 1.5.1
you need to trap the error with something like so: (hack the jquery source)
WARNING: You might run into more places with similar issues so test well.
Just to make it clear this is NOT the most efficient/best way to do this but does make it patently obvious what you/I am doing to work around this.
@Mark 为我指明了正确的方向,我找到了解决方案。
这是此处报告的已知问题 http://bugs.jquery.com/ticket/7071, jquery 团队的人员提供了一个解决方案。 jquery 1.4.4 bugfix 分支中有一个补丁(请参阅此处的讨论https://github。 com/jquery/jquery/pull/13 ),但尚未被拉入 1.4.4 更新或 1.5.1 更新。
据我所见,jquery (src/events.js) 中有 4 个“var elem = e.target, type = elem.type”实例需要替换。你可以“git克隆”分支并自己构建修补过的jquery,或者修补你的副本,或者下载我已经修补过的两个之一(绝对没有保证,yada,yada…):https://gist.github.com/861689。到目前为止,两者似乎都解决了我在问题中描述的具体问题。
@Mark pointed me in the right direction, and I found the solution.
This is a known issue reported here http://bugs.jquery.com/ticket/7071, and there is a solution by the folks on the jquery team. There is a patch sitting in the jquery 1.4.4 bugfix branch (see discussion here https://github.com/jquery/jquery/pull/13 ), but it has not yet been pulled into either the 1.4.4 update or the 1.5.1 update.
From what I can see, there are 4 instances of "var elem = e.target, type = elem.type" in jquery (src/events.js) which need to be replaced. You can "git clone" the branch and build the patched jquery yourself, or patch your copy, or download one of the two I have already patched (absolutely no warranties, yada, yada…): https://gist.github.com/861689. So far, both appear to fix the specific problem which I described in my question.