Home > Web Front-end > JS Tutorial > body text

js copy text content to clipboard implementation code

小云云
Release: 2018-02-24 14:21:49
Original
2301 people have browsed it

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="点击复制代码" />
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!