1、复制内容到剪贴板
const input = document.createElement('input')
input.setAttribute('readonly', 'readonly')
input.setAttribute('value', this.doc)
document.body.appendChild(input)
input.select()
input.setSelectionRange(0, 9999)
document.execCommand('Copy')
document.body.removeChild(input)
2、复制内容到剪贴板(保留换行)
const input = document.createElement('textarea')
// input.setAttribute('value', this.doc) // 这样子不行
input.value = this.doc
document.body.appendChild(input)
input.select()
document.execCommand('Copy')
document.body.removeChild(input)
本文介绍两种将网页内容复制到剪贴板的方法:一种适用于普通文本,另一种适用于包含换行符的文本,确保复制内容格式正确。
7024

被折叠的 条评论
为什么被折叠?



