function copyArticle(event){
const range = document.createRange();
range.selectNode(document.getElementById('dd'));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
$(this).text("已复制");
setTimeout(function(){$("#cp1").text("点击复制")},1000);
}
document.getElementById('cp1').addEventListener('click', copyArticle, false);
利用js实现移动端、pc端通用点击复制
最新推荐文章于 2023-04-06 19:55:57 发布
本文介绍如何通过JavaScript创建范围并利用Selection API实现在网页上复制指定内容,适用于开发者提升用户体验。
2675

被折叠的 条评论
为什么被折叠?



