Home >Web Front-end >JS Tutorial >js copy text content to clipboard implementation code

js copy text content to clipboard implementation code

小云云
小云云Original
2018-02-24 14:21:492374browse

This article mainly shares with you the js copy text content to the clipboard implementation code, I hope it can help everyone.

Compatible with mainstream browsers

<script type="text/javascript">
function copyUrl2()
    {
        var Url2=document.getElementById("biao1").innerText;
        var oInput = document.createElement(&#39;input&#39;);
        oInput.value = Url2;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = &#39;oInput&#39;;
        oInput.style.display=&#39;none&#39;;
        alert(&#39;复制成功&#39;);
    }
</script>
<p cols="20" id="biao1">12345678</p>
<input type="button" onClick="copyUrl2()" value="点击复制代码" />

Related recommendations:

JS example code for copying content to the clipboard (compatible with IE and Firefox )_javascript skills

The above is the detailed content of js copy text content to clipboard implementation code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn