MooTools/JS:bindWithEvent [英] MooTools/JS: bindWithEvent

查看:66
本文介绍了MooTools/JS:bindWithEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的代码库中有这部分内容:

There's this piece in the codebase I'm working on:

this.element.addEvent('click', this.clickEvent.bindWithEvent(this));

我要更改它,以便click事件确保首先加载窗口.所以我尝试了:

I want to change it so that the click event makes sure the window is loaded first. So I tried:

var t = this;
this.element.addEvent('click', function() {
    window.addEvent('load', function() {
        t.clickEvent.bindWithEvent(t));
    });
});

那似乎并没有使它起作用.我想念什么?

That doesn't seem to get it to work though. What am I missing?

推荐答案

您要在用户单击某些内容时在load事件中添加处理程序,而_after the load`事件已经触发.因此,什么也没发生.

You're adding a handler to the load event when the user clicks something, _aftertheload` event has already fired. Therefore, nothing happens.

您可能应该在load事件的事件处理程序中添加click处理程序. (交换两条addEvent行)

You should probably add the click handler inside of an event handler for the load event. (swap the two addEvent lines)

这篇关于MooTools/JS:bindWithEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆