zoukankan      html  css  js  c++  java
  • js兼容安卓和IOS的复制文本到剪切板

    1、在做点击按钮复制功能时遇到了小小的卡顿,此处遇到了两种系统手机的兼容性 / 复制后会对文本进行选中 / 输入法弹出 等。现将方法进行总结,如下代码很好对解决了以上问题,适用性强。

    2、在文本此处使用p标签或者div标签都可

    <div class="copy-font">
    <div class="uuid-code" id="content">saidfh3is21111h</div>
    <button class="btn-copy" id="copyBT">复制</button>
    </div>
    3、采用对原生js,首先对需要复制对文本进行选中节点,检测设备中是否含有其他的复制文本缓存,进行清除。

    将需要复制的文本进行赋值,并调用dom对象的copy功能,返回复制成功提示。

    <script type="text/javascript">
    function copyArticle(event) {
    const range = document.createRange();
    range.selectNode(document.getElementById('content'));

    const selection = window.getSelection();
    if(selection.rangeCount > 0) selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    alert("复制成功!");
    }

    document.getElementById('copyBT').addEventListener('click', copyArticle, false);
    </script>

  • 相关阅读:
    boost::ptree;boost::xml_parser
    boost::array
    boost::timer
    boost::gregorian日期
    boost::algorithm/string.hpp
    boost::lexical_cast
    QT::绘图
    QT::透明
    centos上freefilesync与定时任务
    centos上安装freefilesync工具配置说明
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/11424108.html
Copyright © 2011-2022 走看看