简体   繁体   English

在通过单击复制的 div 中放置小的“已复制”确认

[英]Place small “Copied” confirmation in the div that is copied by click

I have a wordpress site with a DIV that I copy its content via a link using a simple javascript code.我有一个带有 DIV 的 wordpress 站点,我使用简单的 javascript 代码通过链接复制其内容。 I need a message to replace the copied content saying "Copied" in the div AFTER its copied.我需要一条消息来替换复制后在 div 中显示“已复制”的复制内容。

Very challenging.非常具有挑战性。 Need help to do this.需要帮助才能做到这一点。

<div class="btcTXT" id="btc">bc1q978cape6n3sez2ahp59s7jr59j70nqq2x3tt8c</div>
<div onclick="CopyToClipboard('btc');return false;"  class="cpy"><i class="far fa-copy"></i> </div>



<script>
function CopyToClipboard(id)
{
var r = document.createRange();
r.selectNode(document.getElementById(id));
window.getSelection().removeAllRanges();
window.getSelection().addRange(r);
document.execCommand('copy');
window.getSelection().removeAllRanges();
}
</script>

在此处输入图像描述

You're almost there...您快到了...

function CopyToClipboard(id) {
  let item = document.getElementById(id);
  var r = document.createRange();
  r.selectNode(item);
  window.getSelection().removeAllRanges();
  window.getSelection().addRange(r);
  document.execCommand('copy');
  window.getSelection().removeAllRanges();
  item.innerText = 'Copied';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM