博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js实现选中div内容并复制到剪切板
阅读量:4156 次
发布时间:2019-05-25

本文共 570 字,大约阅读时间需要 1 分钟。

function copyUrl  () {

 

        var div = document.getElementById('xxxx');

        if (document.body.createTextRange) {

            var range = document.body.createTextRange();

            range.moveToElementText(div);

            range.select();

        else if (window.getSelection) {

            var selection = window.getSelection();

            var range = document.createRange();

            range.selectNodeContents(div);

            selection.removeAllRanges();

            selection.addRange(range);

            /*if(selection.setBaseAndExtent){

                selection.setBaseAndExtent(text, 0, text, 1);

            }*/

        else {

            console.warn("none");

        }

        document.execCommand("Copy"); // 执行浏览器复制命令

 

        alert("已复制好,可贴粘。");

    }

转载地址:http://uqwxi.baihongyu.com/

你可能感兴趣的文章
关于多目标跟踪的一点理解
查看>>
Learning by tracking:Siamese CNN for robust target association
查看>>
MUSTer:Multi-Store Tracker:A Cognitive Psychology Inspired Approach to Object Tracking
查看>>
Understanding and Diagnosing Visual Tracking Systems
查看>>
Multiple People Tracking by Lifted Multicut and Person Re-identification
查看>>
Visual Tracking Using Attention-Modulated Disintegration and Integration
查看>>
Action-Decision Networks for Visual Tracking with Deep Reinforcement Learning
查看>>
Multiple Object Tracking with High Performance Detection and Appearance Feature
查看>>
深度学习入门(上)-第一章 必备基础知识点
查看>>
相机标定中 calibrateCamera函数介绍
查看>>
重映射和仿射(remap函数)
查看>>
双目定标和双目校正
查看>>
std::nth_elelment排序
查看>>
相机标定中个函数简介
查看>>
RANSAC(随机采样一致算法)原理及openCV代码实现
查看>>
点到直线的距离
查看>>
容器中clear()和erase()的区别
查看>>
OpenCV特征匹配相关结构(KeyPoint&DMatch类型简介)
查看>>
单应矩阵Homography介绍
查看>>
单应矩阵计算 findHomography和getPerspectiveTransform区别
查看>>