0

以 Firefox 中的 JSFiddle 为例

打开控制台并在其中一个字段中输入输入,如果您随后将文本剪掉,请检查控制台中的值。

如果您console.log(e.explicitOriginalTarget);可以看到它包含一个名为 value 的属性,该属性确实包含输入 cut 后的新正确值。但是,在下一行,如果您尝试直接console.log(e.explicitOriginalTarget.value);使用该属性,则会记录切割前输入的先前值。

不知道这是怎么回事?有人有想法么?

我试过做一个 typeof e.explicitOriginalTarget.value 并且它返回我期望的“字符串”。

如果有人能想到关于如何检查输入是否在剪辑中删除了所有文本的任何其他想法,我也对这些持开放态度。我有点被迫在这里使用原型并且相对较新,所以我可能会忽略一些内置功能。

4

1 回答 1

1

The spec says:

The cut event fires before the selected data is removed.

Hence, when the event fires, the .value will be still the one before the cut. If you console.log the event/event target and later inspect it (by clicking on it ;), the change of course will have been made as the event is long done processing at this point. Remember: The target you're logging is a live DOM node.

I'd have a setTimeout(..., 0) to check what the value is like after the cut as a stupidly easy work-around.

Or work with input instead of cut events, if my requirements allowed that...

于 2013-09-12T21:06:17.773 回答