function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("Copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("Copy");
}}
<button id="button1" onclick="CopyToClipboard('copy1')">Click to copy1</button>
<div id="copy1" >Новинка!111</div>
<button id="button2" onclick="CopyToClipboard('copy2')">Click to copy2</button>
<div id="copy2" >Новинка!222</div>
只复制第一个。div
1 个回答