Pure_Eyes 2016-01-01 04:42 采纳率: 0%
浏览 1879

js类中一个方法无法调用弄一个方法

 <!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>

  • 写回答

2条回答 默认 最新

  • 斯洛文尼亚旅游 2016-01-01 06:41
    关注

    你那样给document绑定方法,this对象指向document,不是op的实例

                this.run = function () {
                    var me = this///
                    document.onkeydown = function (e) { me.test(e) }///
                }
    
    评论

报告相同问题?