web建站教程
     
  1. 首页
  2. 前端UI组件库
  3. AI项目和框架
  4. 前端知识
  5. AI应用
  6. IT知识
  7. ComfyUI插件
  8. 地图大全
  9. 休息站

javaScript如何复制粘贴指定标签中的内容

978 ℃

javaScript如何复制粘贴指定div中的内容,下面web建站小编带大家了解一下如何通过document.execCommand('copy')来实现这个功能!

先引入sweetalert.min.css和sweetalert.min.js

复制粘贴实现代码如下:

function copyText(str_file) {
 const btn = document.querySelector('.'+str_file);
 var copy_val = document.getElementById(str_file)
 var copy_file = copy_val.getAttribute("href");
 btn.addEventListener('click',() => {
  const input = document.createElement('input');
  document.body.appendChild(input);
  input.setAttribute('value', copy_file);
  input.select();
  if (document.execCommand('copy')) {
   document.execCommand('copy');
   swal("复制成功!","success");
  }
  document.body.removeChild(input);
 })
}

全新万能复制

带格式复制

Excel如何实现数据的复制粘贴

getElementsByclassName不兼容IE6/7/8解决方法!

html5语法中关于querySelector()基本用法

标签: execCommand querySelector 复制粘贴

上面是“javaScript如何复制粘贴指定标签中的内容”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2738.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 首页 > js
扣子空间 – 免费全能AI办公智能体
Trae:新一代免费的AI编程工具
上一篇:
下一篇:
x 打工人ai神器
x 扫一扫打开藏历小程序

打开微信“扫一扫”查看今日藏历!