
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);
})
}
getElementsByclassName不兼容IE6/7/8解决方法!
标签: execCommand, querySelector, 复制粘贴
上面是“javaScript如何复制粘贴指定标签中的内容”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2738.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

DEDECMS实现在标签中嵌套调用SQL的方法
PubMedPro