사용한 html 소스코드는 다음과 같다.
<style>
.button-group {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
width: 300px;
margin: 0 auto;
}
.text-field {
justify-content: flex-end;
width: 300px;
margin: 0 auto;
}
</style>
<div class="button-group" id="buttonContainer"></div>
<br />
<div class="text-field" id="status"></div>
<script>
const emojiDictionary = '💘💝💖💗💓💞💕❤🧡💛💚💙💜🤎🖤🤍🥰🥹😂😅😢😭🙏👍👏🙌🫶💐🌹🌸✨🔮👑🔥🐥'
const buttonTexts = Array.from(emojiDictionary);
function copyTextToClipboard(text) {
const tempInput = document.createElement('textarea');
tempInput.style.position = 'absolute';
tempInput.style.left = '-9999px';
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
}
function createButtonAndAddEventListener(buttonText) {
const button = document.createElement('button');
button.innerText = buttonText;
button.style.width = '40px';
button.style.height = '40px';
button.style.fontSize = '25px';
button.style.padding = '0';
button.style.textAlign = 'center';
document.getElementById('buttonContainer').appendChild(button);
button.addEventListener('click', function() {
copyTextToClipboard(buttonText);
document.getElementById('status').innerText = buttonText + ' copied!'
});
}
for (const text of buttonTexts) {
createButtonAndAddEventListener(text);
}
</script>
'AI & Code' 카테고리의 다른 글
간단한 HTML details, summary 태그 예제 (0) | 2024.02.20 |
---|---|
간단한 티스토리 자바스크립트 예제1 (0) | 2023.07.24 |
AI 개념정리 02 (응용편) (0) | 2022.12.19 |
AI 개념정리 01 (입문편) (0) | 2022.07.13 |