作者:山中幽水_418 | 来源:互联网 | 2023-01-30 16:18
1> Virk Bilal..:
第1步:改变你的copyToClipboard(element)
喜好:
function copyToClipboard(text) {
var textArea = document.createElement( "textarea" );
textArea.value = text;
document.body.appendChild( textArea );
textArea.select();
try {
var successful = document.execCommand( 'copy' );
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild( textArea );
}
第2步:给你的按钮一个id,然后像这样添加一个事件监听器:
$( '#btnCopyToClipboard' ).click( function()
{
var clipboardText = "";
clipboardText = $( '#txtKeyw' ).val();
copyTextToClipboard( clipboardText );
alert( "Copied to Clipboard" );
});