js实现复制功能
发表于:2024-06-29 11:49:00浏览:421次
我们在做项目的时候,常常需要使用js复制功能,这里记录一下
function copy(content){
// 创建输入框元素
const input = document.createElement('input');//不会保留文本格式
//如果要保留文本格式,比如保留换行符,或者多行文本,可以使用 textarea 标签,再配和模板字符串 ` `
//const input = document.createElement('textarea')
// 将想要复制的值
input.value = content;
// 页面底部追加输入框
document.body.appendChild(input);
// 选中输入框
input.select();
// 执行浏览器复制命令
document.execCommand('Copy');
// 弹出复制成功信息
//this.$message.success('复制成功');
// 复制后移除输入框
input.remove();
}
栏目分类全部>
推荐文章
- php判断字符串是否以http或https开头
- 消息队列Queue
- 500页面
- phpStorm使用正则批量替换
- php10进制转16进制(浮点数)
- mysql报错:SQLSTATE[HY000]: General error: 1881 Operation not allowed when innodb_forced_recovery > 0.
- 在vue中使用setTimeout(function,delay) 和 setInterval(function,delay)
- 使用CURL检测Clinet侧发起的HTTP请求各阶段时间
- layui在弹框中打开页面
- 微信支付错误:Class ‘WechatPay\GuzzleMiddleware\Util\PemUtil’ not found
