jQuery技术: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); }); 
      

      以上就是jQuery教程分享jQuery获取CUT的值相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/548086.html

      (0)
      上一篇 2021年1月13日
      下一篇 2021年1月13日

      精彩推荐