jQuery获取CUT的值

正如您在片段中看到的,我能够获得输入中PASTED的字符串的值。 我想知道是否有一种简单的方法来获取CUTED字符串的值。

$('#example').on("paste cut", function(e) { var value = ''; if(e.type == 'paste') { value = e.originalEvent.clipboardData.getData('text'); } else if(e.type == 'cut') { // How should I get the removed part of the string } $('#result').html(value); }); 
  

使用window.getSelection().toString()解决这个问题:

  $('#example').on("paste cut", function(e) { var value = e.type=='paste' ? e.originalEvent.clipboardData.getData('text') : window.getSelection().toString(); console.log(e.type+': '+value); $('#result').html(value); });