admin管理员组

文章数量:1300135

If this is the equivalent to the jquery bind method, what would it be for the trigger method.

function bind( scope, fn ) {
    return function () {
        fn.apply( scope, arguments );
    };
}

the code above is from another post and it looks the same as a proxy method

you can ment on this too

I have to take the jquery part out off this framework, - this is just the relevant part

if (selector === '') {
              this.el.bind(eventName, method);
            } else {
              this.el.delegate(selector, eventName, method);
            }
          }
        }
      });

      if (includes) result.include(includes);

      return result;
    };

    exports.Controller = mod;
})($, window);

var exports = this;

var Events = {
    bind: function(){
      if ( !this.o ) this.o = $({});
      this.o.bind.apply(this.o, arguments);
    },
trigger: function(){
  if ( !this.o ) this.o = $({});
  this.o.trigger.apply(this.o, arguments);
}
};

thanks

If this is the equivalent to the jquery bind method, what would it be for the trigger method.

function bind( scope, fn ) {
    return function () {
        fn.apply( scope, arguments );
    };
}

the code above is from another post and it looks the same as a proxy method

you can ment on this too

I have to take the jquery part out off this framework, - this is just the relevant part

if (selector === '') {
              this.el.bind(eventName, method);
            } else {
              this.el.delegate(selector, eventName, method);
            }
          }
        }
      });

      if (includes) result.include(includes);

      return result;
    };

    exports.Controller = mod;
})($, window);

var exports = this;

var Events = {
    bind: function(){
      if ( !this.o ) this.o = $({});
      this.o.bind.apply(this.o, arguments);
    },
trigger: function(){
  if ( !this.o ) this.o = $({});
  this.o.trigger.apply(this.o, arguments);
}
};

thanks

Share Improve this question edited Jul 24, 2013 at 12:01 Richard asked Jul 24, 2013 at 11:45 RichardRichard 4,54611 gold badges62 silver badges89 bronze badges 3
  • 3 That code is not at all related to the jQuery bind method. – Barmar Commented Jul 24, 2013 at 11:48
  • oh, do you have a solution, suggestion – Richard Commented Jul 24, 2013 at 11:50
  • 1 See stackoverflow./questions/2490825/… – d4rkpr1nc3 Commented Jul 24, 2013 at 11:54
Add a ment  | 

2 Answers 2

Reset to default 8

It depends on the type of event you wish to trigger. If it's a custom event:

var event = new Event('build');
elem.dispatchEvent(event);

If it's a native event:

var event = new MouseEvent('click');
elem.dispatchEvent(event);

This is of course meant to simulate a mouse event. Other events have their own type.

Once I crossed this site How to Manually Trigger Events in JavaScript

// Here is a VERY basic generic trigger method
function triggerEvent(el, type)
{
    if ((el[type] || false) && typeof el[type] == 'function')
    {
        el[type](el);
    }
}

// We could call this on multiple objects at any time
function resetFields()
{
    triggerEvent(document.getElementById('has-email'), 'onchange');
    triggerEvent(document.getElementById('other-field'), 'onclick');
    triggerEvent(document.getEleemntById('another-one'), 'onblur');
}

本文标签: javascript equivalent to jquery trigger methodStack Overflow