找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 110|回复: 0

FOFHTML置剪辑板内容

[复制链接]

360

主题

45

回帖

1976

积分

管理员

积分
1976
发表于 2025-10-29 15:10:23 | 显示全部楼层 |阅读模式

定义函数 copy(text) {
                // 创建隐藏的div
                常量 div = document.createElement("div");
                div.textContent = text; // 放入要复制的内容
                div.style.position = "fixed";
                div.style.left = "-9999px"; // 隐藏在视野外
                document.body.appendChild(div);

                // 选中div中的文本
                常量 selection = 浏览器窗口.getSelection();
                常量 range = document.createRange();
                range.selectNodeContents(div);
                selection.removeAllRanges();
                selection.addRange(range);

                // 执行复制
                document.execCommand("copy");

                // 清理
                selection.removeAllRanges();
                document.body.removeChild(div);
            }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|久要宝盒 ( 皖ICP备18021237号 )

GMT+8, 2025-12-14 06:57 , Processed in 0.047418 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表