= $(this).parent().find('.code').find('.line').map(function(i, e) { return $(e).text(); }).toArray().join('\n'); var ta = document.createElement('textarea'); var range = document.createRange(); //For Chrome var sel = window.getSelection(); //For Chrome var yPosition = window.pageYOffset || document.documentElement.scrollTop; ta.style.top = yPosition + 'px'; //Prevent page scroll ta.style.position = 'absolute'; ta.style.opacity = '0'; ta.value = code; ta.textContent = code; //For FireFox ta.contentEditable = true; ta.readOnly = false; document.body.appendChild(ta); range.selectNode(ta); sel.removeAllRanges(); sel.addRange(range); ta.setSelectionRange(0, code.length); var result = document.execCommand('copy'); if (result) $(this).text('复制成功'); else $(this).text('复制失败'); ta.blur(); //For iOS $(this).blur(); })).on('mouseleave', function(e) { var $b = $(this).find('.copy-btn'); setTimeout(function() { $b.text('复制'); }, 300); }).append(e); })