下面是一个来自w3学校的简单示例,它使用一点JS来复制输入字段的值。
<input type="text" value="StackExchange WordPress" id="myInput">
<button onclick="myFunction()">Copy text</button>
<p>The document.execCommand() method is not supported in IE9 and earlier.</p>
<script>
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.value);
}
</script>
在此处找到的源:
w3schools