如图有这么一段文字,如果用鼠标选中然后ctrl+c,粘贴到文本框中
粘贴后的效果如下:
现在是想实现提供一个copy按钮,点复制的时候能够复制内容,现在是这么做的:
let app = document.getElementById('app')
var txt= document.getElementById('txt').innerText
var oInput = document.createElement('input')
oInput.value = txt
app.appendChild(oInput)
oInput.select()
document.execCommand('Copy')
oInput.id = 'copyInpu'
oInput.style.display = 'none'
this.$message({
message: ''邮件内容已经复制到剪贴板!'',
type: 'success',
duration: 5000
})
app.removeChild(oInput)
但是js一键复制后粘贴到文本框中的效果如下:
js如何模拟实现鼠标选中然后ctrl+c复制粘贴到文本框能保留换行的效果?
你可以创建一个
textarea
试试,可以保存格式