[英]Cannot copy text to clipboard
I want to copy some text that is written to the clipboard.我想复制一些写入剪贴板的文本。
I created the following function:我创建了以下函数:
function copyTextToClipboard(){
document.getElementById("contactsInfo").select();
document.getElementById("contactsInfo").setSelectionRange(0, 99999)
document.execCommand("copy");
}
That is called when the user clicks on the element:当用户点击元素时调用:
document.getElementById("contactsInfo").addEventListener("click", ()=>{
copyTextToClipboard();
})
The element in HTML: HTML 中的元素:
<div class="information-container">
<p id="contactsInfo">Email: allab.di@ubi.pt</p>
<p id="contactsInfo">Phone: +310961810340</p>
<p id="contactsInfo">Street: Bolama</p>
</div>
It isn't copying it though, what is the problem?它不是复制它,但有什么问题?
I want to copy some text that is written to the clipboard.我想复制一些写入剪贴板的文本。
I created the following function:我创建了以下函数:
function copyTextToClipboard(){
document.getElementById("contactsInfo").select();
document.getElementById("contactsInfo").setSelectionRange(0, 99999)
document.execCommand("copy");
}
That is called when the user clicks on the element:当用户点击元素时调用:
document.getElementById("contactsInfo").addEventListener("click", ()=>{
copyTextToClipboard();
})
The element in HTML: HTML 中的元素:
<div class="information-container">
<p id="contactsInfo">Email: allab.di@ubi.pt</p>
<p id="contactsInfo">Phone: +310961810340</p>
<p id="contactsInfo">Street: Bolama</p>
</div>
It isn't copying it though, what is the problem?它不是复制它,但有什么问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.