我想制作一个带有重置和复制到剪贴板按钮的html表单,而不会在取消选中复选框时丢失文本框中的文本
答案 0 :(得分:0)
您可以使用以下内容从输入中复制内容:
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
copyTextarea.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');
}
});