我在无数不同的网站上看到过这种事情。如果我不知道它的名字,我很抱歉,但这里有一个例子:
查看文本框和地址字符串的位置,以便通过复制按钮轻松复制。我想知道如何在WordPress中做到这一点,或者是否可以在WordPress中使用javascript代码?如何添加一个只读文本框,其中的文本具有复制按钮?
1 个回复
最合适的回答,由SO网友:colbyalbo 整理而成
下面是一个来自w3学校的简单示例,它使用一点JS来复制输入字段的值。
<input type="text" value="StackExchange WordPress" id="myInput">
<button onclick="myFunction()">Copy text</button>
<p>The document.execCommand() method is not supported in IE9 and earlier.</p>
<script>
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.value);
}
</script>
在此处找到的源:w3schools结束