问题描述
我有几个这样的听众,听取点击,然后显示< div id =c50>< a hre ...> CONTENT< / a>< ; / div>
(在这种情况下)。一切都适用于Opera,Chrome和FF,但不适用于IE。
I have several listeners like this, which listen to click and then displays content within <div id="c50"><a hre...>CONTENT</a></div>
(in this case). Everything works in Opera, Chrome and FF, but not in IE.
google.maps.event.addListener(pano50, 'click', function() {
fireEvent(document.getElementById("c50").getElementsByTagName("a")[0], 'click');
})
Chrome javascript控制台工具在点击后显示此错误(但工作正常):
Chrome javascript console tool displays this error after click (but works fine):
Uncaught TypeError: object is not a function
但传统上, IE8显示:
but traditionally, IE8 displays:
Function expected on line 817
这是上面第一行代码,点击后什么都不做。感谢您的任何建议!
which is the first line of code above and do nothing after click. Thank you for any advice!
编辑:这是fireEvent函数:
here is the fireEvent function:
function fireEvent(element, event) {
if (document.createEventObject){
/* for IE */
return element.fireEvent('on' + event, document.createEventObject());
}else{
/* for other browsers */
var evt = document.createEvent('HTMLEvents');
evt.initEvent(event, true, true);
}
return !element.dispatchEvent(evt);
}
推荐答案
你有MooTools在运行在上。 MooTools使用适用于所有浏览器。 MooTools的版本的fireEvent()
需要点击而不是onclick。
You've got MooTools running on your page. MooTools overrides IE's built-in element.fireEvent()
method with its own normalized method that works for all browsers. MooTools' version of fireEvent()
expects "click" instead of "onclick".
你可以修复这个通过简单地更改 fireEvent
函数来使用click而不是onclick来解决问题:
You can fix this one issue by simply changing your fireEvent
function to use "click" instead of "onclick":
/* for IE */
return element.fireEvent(event, document.createEventObject());
但是,因为MooTools规范化 element.fireEvent
要使用所有浏览器,您可以放弃 fireEvent
函数,而只需调用 element.fireEvent()
直接。
But, since MooTools normalizes element.fireEvent
to work with all browsers, you may be able to ditch your fireEvent
function, and instead just call element.fireEvent()
directly.
您可能遇到更大的问题。你正在使用MooTools和jQuery,这是好的,但是如果你不知道你在做什么,你可能会很快遇到麻烦。
You may have bigger problems. You are using MooTools and jQuery side by side which is ok, but if you don't know what you are doing, you can get into trouble quickly.
这篇关于JavaScript错误“预期功能”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!