📅  最后修改于: 2022-03-11 14:53:31.049000             🧑  作者: Mango
const copyWithStyle = ( element ) => {
const doc = document;
const text = doc.getElementById( element );
let range;
let selection;
if( doc.body.createTextRange ) {
range = doc.body.createTextRange();
range.moveToElement( text );
range.select();
} else if ( window.getSelection ) {
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents( text );
selection.removeAllRanges();
selection.addRange( range );
}
document.execCommand( 'copy' );
window.getSelection().removeAllRanges();
document.getElementById( 'clickMe' ).value = 'Copied to clipboard!';
}