-
09-06
-
12-27
-
12-31
-
01-08
-
12-31
JavaScript 高兼容复制内容代码
发布时间:2021-01-08 13:02:15
文章来源:原创
访问次数:42
<body>
<span id="copy1">你好啊!</span>
<input type="text" value="你好!"id="copy2">
<!--onClick="CopyAdd()" 点哪里加哪里-->
<button id="copy3" onClick="CopyAdd()">复制</button>
<script>
function CopyAdd(event) {
const range = document.createRange();
range.selectNode(document.getElementById('copy2'));//复制对象ID
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}
</script>
</body>本文链接:http://35.aizhanju.cnhttp://35.aizhanju.cn/javascript/78.html
文章评论
共 0 条评论,查看全部
- 这篇文章还没有收到评论,赶紧来抢沙发吧~
最新资讯


粤公网安备 34018102340473号
中国互联网举报中心