javascript - 调用mootools类中的方法

标签 javascript methods mootools

我有一个关于在 mootools 中调用其他函数的问题类(class)。例如:

var f = new Class('foo',
{
  test1: function(){
    var table = new Element(...);
    ...

    $(table).getElements('input').each(function(input) {
      input.addEvent('change', function() {
        // how could I call test2 and pass the input element?
      })
    });
  },
  test2: function(e){
    alert(e);
  }    
});

谢谢。

最佳答案

var f = new Class('foo',
{
    test1: function(){
        var table = new Element(........);
        var me = this;
         $(table).getElements('input').each(function(input) {
                    input.addEvent('change', function() {
                        me.test2("foo");
                    }); 
            });
        },
    test2: function(e){
                alert(e);
        }
});

关于javascript - 调用mootools类中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1580846/

相关文章:

javascript - Queryselector 返回 null,不知道为什么

C#方法等待用户点击

java - 将异常传递给自定义异常处理程序方法。 java

Javascript - 替换()方法的反向?

javascript - 如何使用 Mootools 或 Javascript 在点击时激活样式类?

javascript - 使用 jQuery 获取链接的属性并将其作为表单发布到另一个脚本文件

javascript - 多少 JSON 是太多的 JSON?

javascript - 将 Json 导入 html(表)

javascript - mootools。无法在 iframe 中获取 DOM 元素

javascript - 在 Mootools 中解析 XML