我试图弄清楚如何从 JavaScript 复制字符串和粘贴。
此代码示例:
function copyLink() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
}
副本来自myInput value:
<input type="text" value="ttps://site.org/" id="myInput">
但我正在尝试从变量中复制文本,不包括html value:
<button onclick="copyText()">Copy text</button>
这是.js为了允许用户复制/粘贴:
function copyText() {
var text = "long text...";
...
}
它看起来很简单,但似乎我搜索不正确,因为我找不到方法。