+
95
-

原生js如何实现文本点击复制?

请问原生js如何实现文本点击复制?

网友回复

+
15
-

可以使用浏览器的复制api: document.execCommand("copy"); 完整代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">

    <style type="text/css">
        .wrapper {
            position: relative;
        }
        #input {
            position: absolute;
            top: 0;
            left: 0;
            opacity: 0;
            z-index: -10;
        }
    </style>
</head>
<body>


    <div class="wrap...

点击查看剩余70%

我知道答案,我要回答