gpt4 book ai didi

twitter-bootstrap - vue-clipboard2 在 bootstrap-vue 模态中不起作用

转载 作者:行者123 更新时间:2023-12-04 14:45:49 24 4
gpt4 key购买 nike

我在 bootstrp-vue 模态中使用了 vue-clipboard2 插件。但是文本不是复制的。

然后我尝试在 bootstrap-vue 模态中使用 vanilla js 复制到剪贴板。但是文本不是复制的。

任何人都可以找出问题所在??

最佳答案

以下内容对我有用并使用新的 Clipboard API writeText method大多数现代浏览器都支持它(请参阅 Can I use 了解更多详细信息)并且不需要 vue-clipboard。

//If you want to copyText from Element
function copyTextFromElement(elementID) {
let element = document.getElementById(elementID); //select the element
let elementText = element.textContent; //get the text content from the element
copyText(elementText); //use the copyText function below
}

//If you only want to put some Text in the Clipboard just use this function
// and pass the string to copied as the argument.
function copyText(text) {
navigator.clipboard.writeText(text);
}
<div id="mytext">This is some text that needs to be copied</div>
<button onclick="copyTextFromElement('mytext')">Copy</button>

关于twitter-bootstrap - vue-clipboard2 在 bootstrap-vue 模态中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57304680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com