这是我的代码,但是不起作用。
btn.addEventListener("click", function () {
var get = document.getElementById('myTxtArea').value
var res = get.split(/[ ,-]+/).join(';')
textarea.innerText = res
res.select();
document.execCommand('copy');
})
W3:https://www.w3schools.com/howto/howto_js_copy_clipboard.asp
SO的另一篇文章:单击按钮时将文本区域的文本复制到剪贴板中
看来您有复杂的事情,超出了他们所需要的。尝试这个:
function copy() {
let textarea = document.getElementById("textarea");
textarea.select();
document.execCommand("copy");
}
要么
function myFunction() {
/* Get the text field */
var copyText = document.getElementById("myInput");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句