zoukankan      html  css  js  c++  java
  • 关于div可编辑的复制粘贴问题

     1  todoFilter(e) {
     2                 e.preventDefault();
     3                 if (!e.target.getAttribute('contenteditable')) {
     4                     return;
     5                 }
     6                 const cpTxt = e
     7                     .clipboardData
     8                     .getData('text');
     9     
    10                 const selection = window.getSelection ? window.getSelection() : document.selection;
    11                 if (!selection.rangeCount) return;
    12                 const range = selection.createRange ? selection.createRange() : selection.getRangeAt(0);
    13                 window._range = range;
    14                 if (!window.getSelection) {
    15                     range.pasteHTML(cpTxt);
    16                     range.collapse(false);
    17                     range.select();
    18                 } else {
    19                     range.collapse(false);
    20                     const hasR = range.createContextualFragment(cpTxt);
    21                     let hasR_lastChild = hasR.lastChild;
    22                     while (hasR_lastChild && hasR_lastChild.nodeName.toLowerCase() == 'br' && hasR_lastChild.previousSibling && hasR_lastChild.previousSibling.nodeName.toLowerCase() == 'br') {
    23                         var e = hasR_lastChild;
    24                         hasR_lastChild = hasR_lastChild.previousSibling;
    25                         hasR.removeChild(e);
    26                     }
    27                     range.insertNode(hasR);
    28                     if (hasR_lastChild) {
    29                         range.setEndAfter(hasR_lastChild);
    30                         range.setStartAfter(hasR_lastChild);
    31                     }
    32                     selection.removeAllRanges();
    33                     selection.addRange(range);
    34                 }
    35             },
    View Code
  • 相关阅读:
    Tree Recovery解题报告
    bjtuOJ1019 Robot
    bjtuOJ1137 蚂蚁爬杆
    栈的使用,rails
    重做catch the cow
    C#3.0新特性之匿名类型
    C#Lambda表达式的用法
    C#进程的使用方法详解
    C#进程管理启动和停止
    C#LINQ查询表达式用法
  • 原文地址:https://www.cnblogs.com/huenchao/p/8253144.html
Copyright © 2011-2022 走看看