<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function ui(){
this.we=function(){
alert("wed");
}
this.test=function(e){
var t=e.which
this.we();
}
this.run=function(){
document.onkeydown=this.test;
}
}
function op(){
var r=new ui();
r.run();
}
op();
</script>
</body>
</html>

js类中一个方法无法调用弄一个方法
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- 斯洛文尼亚旅游 2016-01-01 06:41关注
你那样给document绑定方法,this对象指向document,不是op的实例
this.run = function () { var me = this/// document.onkeydown = function (e) { me.test(e) }/// }
解决 无用评论 打赏 举报