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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM