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