未捕获的TypeError:undefined不是javascript中的函数 [英] Uncaught TypeError: undefined is not a function in javascript
本文介绍了未捕获的TypeError:undefined不是javascript中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script type = text / javascript语言= javascript>
window 。 history .forward( 1 < /跨度>);
document .attachEvent( keydown,my_onkeydown_handler);
function my_onkeydown_handler(e){
switch (e.keyCode){
case 116 : // F5;
e.returnValue = false ;
e.keyCode = 0 ;
window .status = 我们已停用F5\" 跨度>;
break ;
}
}
< / script>
这是我在javascript
中的代码,但它显示错误Uncaught TypeError:undefined is a a a a函数
我的代码有什么问题?
解决方案
只在IE中支持attachEvent函数。这是一个非标准的功能,你不应该使用它!
使用 addEventListener [ ^ ]而不是!
使用addEventListener而不是attachEvent(不再支持)。
http:// msdn。 microsoft.com/en-us/library/ie/ms536343%28v=vs.85%29.aspx [ ^ ]
window.history .forward(1);
document。 addEventListener (keydown,my_onkeydown_handler);
function my_onkeydown_handler(e){
开关(e.keyCode){
案例116:// F5;
e.returnValue = false;
e。 keyCode = 0;
window.status =我们禁用了F5;
休息;
}
}
<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("keydown", my_onkeydown_handler);
function my_onkeydown_handler(e) {
switch (e.keyCode) {
case 116: // F5;
e.returnValue = false;
e.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>
This is my code in javascript
but it shows the error "Uncaught TypeError: undefined is not a function"
what is wrong with my code ?
解决方案
attachEvent function is only supported in IE. It's a not standard function and you should not use it!
Use addEventListener[^] instead!
Use addEventListener instead of attachEvent(no longer supported).
http://msdn.microsoft.com/en-us/library/ie/ms536343%28v=vs.85%29.aspx[^]
window.history.forward(1);
document.addEventListener("keydown", my_onkeydown_handler);
function my_onkeydown_handler(e) {
switch (e.keyCode) {
case 116: // F5;
e.returnValue = false;
e.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
这篇关于未捕获的TypeError:undefined不是javascript中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文