admin 管理员组文章数量: 1086019
It used to work but now I get a:
window.event is undefined
From this simple code that used to work:
function checkKey() {
if (window.event.keyCode != 9) {
document.actionForm.saveStatus.value = "Not saved";
}
}
Why can't I use window.event anymore?
It used to work but now I get a:
window.event is undefined
From this simple code that used to work:
function checkKey() {
if (window.event.keyCode != 9) {
document.actionForm.saveStatus.value = "Not saved";
}
}
Why can't I use window.event anymore?
Share Improve this question asked Oct 29, 2012 at 9:45 Niklas RosencrantzNiklas Rosencrantz 26.7k77 gold badges243 silver badges444 bronze badges3 Answers
Reset to default 4window.event
is a proprietary Microsoftism.
The standard way to access data about an event is via the first argument of the event handler function.
function checkKey(e) {
var evt = e || window.event,
keyPressed = evt.which || evt.keyCode;
if (keyPressed != 9) {
document.actionForm.saveStatus.value = "Not saved";
}
You can standardize the check like so:
function checkKey(e) {
var evt = e || window.event;
if (evt.keyCode != 9) {
document.actionForm.saveStatus.value = "Not saved";
}
}
本文标签: javascriptWhy is windowevent not workingStack Overflow
版权声明:本文标题:javascript - Why is window.event not working? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744083909a2530763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论