【发布时间】:2022-01-20 02:49:01
【问题描述】:
我有这个代码:
<button onclick="copyStringToClipboard(this.getAttribute('data-target'))" id = 'accbtn1' data-target="accbtn1" class="copy_btn"> mypassword </button>
<script>
function copyStringToClipboard (target) {
var str = document.getElementById(target).innerText;
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>
我只需要“mypassword”这个词从按钮中隐藏但不隐藏按钮。有没有办法复制我在html代码中设置的单词而不显示它?
非常感谢
【问题讨论】:
-
现在我删除了我的第一个答案,看第二个答案