web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

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

497 ℃
     

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()基本用法

vuejs如何实现复制粘贴功能

vuejs实现el-input复制粘贴功能

标签: execCommand, querySelector, 复制粘贴

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

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

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

当前位置: 网站首页 > js
本文共计579个字,预计阅读时长4分钟
生活小工具,收录了80多款小工具
上一篇: 推荐2款充满科技感的艺术字体——小新黑体、小新潮酷体
下一篇: 推荐一款浏览器数据库的开源工具库——Dexie.js(JavaScript调用)
x 打工人ai神器