我试图在我的 html 页面上获得一个复制按钮,但它不起作用 - 在 chrome 控制台中它什么也没说,它只是不会复制文本。
这是我的 html:
<!doctype html>
<div class="ipDiv tk-saffran">
<div class="ipText">
<h2 id="ip">play.MineGlade.net</h2>
</div>
<div class="copyButton">
<button onclick="copyIp()">Copy IP</button>
<script>
function copyIp() {
var copyText = document.getElementById("ip");
copyText.select;
document.execCommand("Copy");
}
</script>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我该如何解决?