现在的位置: 首页 > 综合 > 正文

.triggerHandler()与.trigger()的不同点

2019年10月31日 ⁄ 综合 ⁄ 共 948字 ⁄ 字号 评论关闭

The .triggerHandler() method
behaves similarly to .trigger(),
with the following exceptions:

.triggerHandler()方法与.trigger()方法相似,除了:

  • The .triggerHandler() method
    does not cause the default behavior of an event to occur (such as a form submission).
1)  .triggerHandler()方法不会触发事件的默认行为,如表单提交;
  • While .trigger() will
    operate on all elements matched by the jQuery object,.triggerHandler() only
    affects the first matched element.
2) .trigger()会操作每一个匹配的jQuery对象,而.triggerHandler()只会对第一个匹配的元素产生作用;
  • Events created with .triggerHandler() do
    not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.
3) 由.triggerHandler()产生的事件不会沿着DOM分层冒泡;如果它没有直接被目标元素处理,则什么也不做;
  • Instead of returning the jQuery object (to allow chaining), .triggerHandler() returns
    whatever value was returned by the last handler it caused to be executed. If no handlers are triggered, it returns undefined

4).triggerHandler()不返回jQuery对象,而返回它所触发的最后一个处理事件中返回的值。所以若没有句枘被触发,则它返回undefined

For more information on this method, see the discussion for .trigger().

抱歉!评论已关闭.