zoukankan      html  css  js  c++  java
  • jq 点击复制div里面的内容 如果粘贴到富文本中,会将样式,里面所有的标签,文字一并粘贴进去

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>点击复制功能</title>
    </head>
    <script src="http://code.jquery.com/jquery-2.0.2.min.js"></script>
        <style>
            .popup__bottom__text{
                margin-bottom: 10px;
            }
        </style>
    <body>
        <div class="popup__bottom__text">
            <a  id="text_1" style="font-size:12px; color:#0066cc;" href="/ueditor/php/upload/file/20181016/1539677909627575.png" title="1539677909627575.png">bbbb.png</a>
            <a href="javascript:(0)" onclick="tapCopy('text_1')">点我复制</a>
        </div>
        <div class="popup__bottom__text">
            <a  id="text_2" style="font-size:12px; color:#0066cc;" href="/ueditor/php/upload/file/20181016/1539677909627575.png" title="1539677909627575.png">aaaa.png</a>
            <a href="javascript:(0)" onclick="tapCopy('text_2')">点我复制</a>
        </div>
        
    </body>
    </html>
    <script>
        //复制文本
        function tapCopy($id) {
         //var $id = $(dom).prev().attr('data_id'); selectText($id); document.execCommand(
    'copy'); alert('复制成功'); } //选中文本 function selectText(element) { var text = document.getElementById(element); //做下兼容 if (document.body.createTextRange) { //如果支持 var range = document.body.createTextRange(); //获取range range.moveToElementText(text); //光标移上去 range.select(); //选择 } else if (window.getSelection) { var selection = window.getSelection(); //获取selection var range = document.createRange(); //创建range range.selectNodeContents(text); //选择节点内容 selection.removeAllRanges(); //移除所有range selection.addRange(range); //添加range /*if(selection.setBaseAndExtent){ selection.setBaseAndExtent(text, 0, text, 1); }*/ } else { alert("复制失败"); } } </script>
  • 相关阅读:
    SQL 中 Left Join 转为 Inner Join 的实际应用
    结合 Mybatis,探讨 Oracle 中 in 与 not in 的陷阱
    一个“保存”按钮同时存在“增删改”三种操作,该如何去实现?
    边边角角
    NIPS2017-The neural hawks process
    第一届山东省ACM——Phone Number(java)
    第一届山东省ACM——Balloons(java)
    java 解 poj 1000
    poj Flip Game 1753 (枚举)
    ACM交流赛感悟
  • 原文地址:https://www.cnblogs.com/zc290987034/p/9803992.html
Copyright © 2011-2022 走看看