Opera 无法识别我绑定到表单“提交”的事件处理程序事件
编辑:这个问题很愚蠢,因为我在其他地方犯了一个错误导致了它。
我决定今天在 Opera 上测试我的网站,因为它在 Chrome 和 FF 中运行得很好。所以我下载了最新的 Ubuntu 版 Opera 并尝试登录我的网站。 BLEH。
由于某种原因,它无法识别我绑定到表单的“提交”事件的任何函数,我需要验证等。我有通常的 addEvent(element, eventtype,callback)
来执行相关操作调用 addEventListener
或 attachEvent
。
正如我所说,这在 Chrome 和 Firefox 中都能完美运行。我什至尝试过
addEvent(loginForm, 'submit', function(){alert("It works");});
,但根本没有任何反应。因此,它甚至不是像我首先想到的那样停止默认操作,而是实际上根本不绑定事件!对于上面的示例,我可以确认 loginForm
确实包含对实际表单元素的引用。
有人知道 Opera 发生了什么事吗?
编辑:下面是我的 addEvent
函数
function addEvent (obj, evt, callback) {
if (evt=="mousewheel")
evt = (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel"
if (obj.addEventListener){
obj.addEventListener(evt, callback, false);
} else {
obj.attachEvent("on" + evt, callback);
}
}
Edit: This question is silly, as I had a mistake somewhere else that led to it.
I decided I'd test out my site on Opera today seeing that it works perfectly in Chrome and FF.. So I downloaded the latest Opera for Ubuntu and tried to log into my site. BLEH.
For some reason it is not recognising any functions I bind to the "submit" event of forms, which I need for validation etc. I have the usual addEvent(element, eventtype, callback)
which performs the relevant call to either addEventListener
or attachEvent
.
As I said, this works perfectly in both Chrome and Firefox. I even tried
addEvent(loginForm, 'submit', function(){alert("It works");});
but had no response at all. So it's not even about stopping the default action as I'd first thought, but doesn't actually bind the event at all! With regard to the above example, I can confirm that loginForm
does contain a reference to the actual form element.
Does anybody have any idea what is going on with Opera?
EDIT: Below is my addEvent
function
function addEvent (obj, evt, callback) {
if (evt=="mousewheel")
evt = (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel"
if (obj.addEventListener){
obj.addEventListener(evt, callback, false);
} else {
obj.attachEvent("on" + evt, callback);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是另一个无耻的框架插件...
我不知道你是否热衷于添加一点 YUI/jquery :D
Here goes another shameless framework plug...
Idk if you're keen on adding a bit of YUI/jquery or not :D
我复制了你的代码,见下文:
它有效。虽然我目前在 PC 上运行 Opera。
您是否尝试过使用 Dragonfly 看看是否有错误?
I copied your code, see below:
And it works. Although I'm currently on a PC in Opera.
Have you tried using Dragonfly to see if there is any errors?