js 点击复制内容

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试实例</title>
<script>
function myFunction(message)
{

    var input = document.createElement("input");
        input.value = message;
        document.body.appendChild(input);
        input.select();
        input.setSelectionRange(0, input.value.length), document.execCommand('Copy');
        document.body.removeChild(input);
        alert("复制成功", "text");
}
</script>
</head>
 
<body>
<div onclick="myFunction('要复制的内容')">点我</div>
</body>
</html>

 

 

参考文章:https://blog.csdn.net/Developersq/article/details/100522751

posted @ 2019-10-07 18:32  钧一  阅读(778)  评论(0编辑  收藏  举报