Шаблоны кода
Шаблон генератора на кадклуб
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <title>Document</title> </head> <body> <div class="row"> <div class="col s12 m4 offset-m4"> <h4>Генератор кода случайных чисел</h4> <label for="">Первое число <br> <input type="text" class="firstNum"></label> <br> <label for="">Второе число<br> <input type="text" class="secondNum"></label> <br> <textarea name="" id="" cols="30" rows="10" class="tel"></textarea> <button class="btn" onclick="codeRandom(); return false;">Генерировать</button> <div class="output"></div> </div> </div> <script> function codeRandom() { let output = document.querySelector('.output'); output.innerHTML =``; } </script> </body> </html>
Copy
Скрипт кнопки Копировать множественная
// скрипт кнопки копировать код const copyText = document.querySelectorAll('.copy'); const copyButton = document.querySelectorAll('.copyButton'); for(let i = 0; i < copyButton.length; i++) { copyButton[i].addEventListener('click', () => { let textToCopy = copyText[i].textContent; navigator.clipboard.writeText(textToCopy).then(() => { alert('Текст скопирован в буфер обмена'); }).catch((err) => { alert('Ошибка при копировании текста: ', err); }); }); }
Copy
Сама кнопка копировать
Copy
Copy
Скрипт кнопки Копировать одиночная
function copyToClipboard() { const output1 = document.querySelector('.output1'); const text = document.querySelector('.copy').value; navigator.clipboard.writeText(text) .then(() => { output1.innerHTML = `
Текст скопирован в буфер обмена:
${text}`; }) .catch((error) => { output1.innerHTML ="Не удалось скопировать текст: "; }); }
Copy
Сама одиночная кнопка копировать
Copy
Copy
Скрипт кнопки Очистить
function clearOutput() { const output = document.querySelector('.output'); const output1 = document.querySelector('.output1'); const textArea = document.querySelector('.text'); output.textContent = ''; output1.textContent = ''; textArea.value = ''; output.classList.remove('add'); // Remove the 'add' class output1.classList.remove('add1'); // Remove the 'add1' class }
Copy
Сама кнопка Очистить
Очистить
Copy