nt.createElement('textarea') document.body.appendChild(ta) ta.style.position = 'absolute' ta.style.top = '0px' ta.style.left = '0px' ta.value = code ta.select() ta.focus() var result = document.execCommand('copy') document.body.removeChild(ta) if(result)$(this).text('复制成功') else $(this).text('复制失败') $(this).blur() })).on('mouseleave', function (e) { var $b = $(this).find('.copy-btn') setTimeout(function () { $b.text('复制') }, 300) }).append(e) })