<span id="copyText">123456</span>
<span onclick="copy();">复制</span>
function copy() {
var text =document.getElementById("copyText").innerText;
var input = document.createElement('input');
input.setAttribute('id', 'copyInput');
input.setAttribute('value', text);
document.getElementsByTagName('body')[0].appendChild(input);
document.getElementById('copyInput').select();
if (document.execCommand('copy')) {
alertinfo('复制成功');
}
document.getElementById('copyInput').remove();
}
js复制span内容到剪切板
最新推荐文章于 2024-03-20 14:58:12 发布