<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js剪切板功能</title>
</head>
<body>
<span onclick="copy()">copy</span>
<textarea name="" id="text" cols="30" rows="10"></textarea>
<script>
function copy() {
var text = document.getElementById("text");
text.value = "你好!";
text.focus();
text.select();
setTimeout(function(){
document.execCommand("copy");
alert("coyp done!")
}, 1500)
}
</script>
</body>
</html>