У меня есть вопрос ^^;
Я хочу скопировать ввод в буфер обмена, нажав copy1 с помощью js или jquery
Я хочу скопировать текстовую область в буфер обмена, нажав copy2
Спасибо, если дадите мне знать, как.
==============================================
Я искал какой-то код для этого, но это было сложно.
Я применил этот код
$("#copy_code").click(function(e) {
e.preventDefault();
document.execCommand('copy', false, document.getElementById('select-this').select());
alert("copy is completed")
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="" value="{{p.content1}}" size="40">
<button class="btn btn-outline-primary btn-sm myinput" id="copy_code select-this">copy1</button>
ех)
https://codepen.io/fabean/pen/GprQJa
но ошибка
Uncaught TypeError: Cannot read property 'select' of null
at HTMLButtonElement.<anonymous> ((index):251)
at HTMLButtonElement.dispatch (custom.js:3)
at HTMLButtonElement.q.handle (custom.js:3)