【问题标题】:Take action after standard events action is completed在标准事件操作完成后采取行动
【发布时间】:2015-07-30 13:33:31
【问题描述】:

我需要在标准动作完成后执行一些动作。与event.preventDefault()相反的东西

这是我需要的示例:

$contentEditable.on('paste', function (event) {

  event.doWhatYouNeedToDo();

  // here I will use `range` object to grab cursor position
  // and take some additional actions with inserted text

});

以下是事件如何运作的示例:https://jsfiddle.net/5emcf8rw/

在执行标准操作(文本更改)之后,我需要在某处处理文本

这是@A 建议的解决方案。沃尔夫

$contentEditable.on('paste', function (event) {
  setTimeout(function () {
      // do whatever you want here
  }.bind(this), 0);
});

我们能否确定标准动作完成后触发超时功能?

【问题讨论】:

  • 通过说 $contentEditable.on('paste', function (event) {,您正在添加一个额外的回调以及事件的默认回调。因此,当您注册事件处理程序时,您正在做“doWhatYouNeedToDo”
  • 我觉得你错了jsfiddle.net/5emcf8rw
  • 您正在寻找的预期行为是什么。
  • 等一下。编辑问题
  • @kakabomba 那么在发布的答案中延迟它有什么问题??? jsfiddle.net/5emcf8rw/1 Paste 事件在粘贴数据之前被触发,没有事件“粘贴”所以...

标签: javascript jquery events javascript-events event-handling


【解决方案1】:

您可以使用超时将其延迟一点:

$contentEditable.on('paste', function (event) {
    setTimeout(function () {
        // do whatever you want here
    }.bind(this), 0);
});

【讨论】:

  • 我不知道更好
  • 我有复杂的 dom 树,我不知道标准操作需要多长时间
  • 触发的时间应该总是少于超时回调
猜你喜欢
  • 2017-06-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-10
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
相关资源
最近更新 更多