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

js copy text content to clipboard implementation code

小云云
Release: 2018-02-24 14:21:49
Original
2382 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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template