Jquery 复制时在文章中间添加一个URL

Jquery 复制时在文章中间添加一个URL,jquery,Jquery,因此,我计划在复制内容后将特定url粘贴到剪贴板中。 因此,URL将在文章的中间,而不是在内容的开头或结尾。例如: 复制前: hello world.. hello world.. hello world.. hello world.. hello world.. hello world.. https://stackoverflow.com hello world.. hello world.. 复制后,以下内容保存在剪贴板上: hello world.. hello world.. he

因此,我计划在复制内容后将特定url粘贴到剪贴板中。 因此,URL将在文章的中间,而不是在内容的开头或结尾。例如:

复制前:

hello world..
hello world..
hello world..
hello world..
hello world..
hello world..
https://stackoverflow.com
hello world..
hello world..
复制后,以下内容保存在剪贴板上:

hello world..
hello world..
hello world..
hello world..
hello world..
hello world..
https://stackoverflow.com
hello world..
hello world..

有没有办法使用jQuery实现这一点?

这在纯JavaScript中是可能的

单击“复制到剪贴板”按钮时,将复制一个包含
div\content
的字符串,其中包括一个在DOM中不可见的链接

const$contentDiv=document.getElementById('content'))
const$insertLink=document.getElementById('insert-link'))
const$copyBtn=document.getElementById('copy-btn')
var copyText=(textToCopy)=>{
const testextarea=document.createElement('textarea')
testextarea.value=textToCopy
document.body.appendChild(区域)
testextarea.select()
document.execCommand('copy')
document.body.removeChild(外部区域)
}
$copyBtn.addEventListener('单击',()=>{
copyText($contentDiv.textContent)
})
#插入链接{
显示:无;
}

Lorem
ipsum
dolor
坐在阿梅特。

复制到剪贴板< /代码>是的,所有内容都被复制,加上内容中间的某个URL。