클릭시 복사버튼 여러개 채택완료
인찌
3년 전
조회 2,666
게시판 리스트 페이지에 버튼 클릭하면 여분필드 wr_7의 텍스트가 복사대는 것을 구현하였습니다.
근데 리스트페이지다보니깐 버튼이 여러개인데 하나만.. 복사 기능이 되더라구요
혹시 버튼이 여러개라서 해당 여분필드 값이 각각 복사되게 어떻게 할수 있을까요?
</p>
<p><div class="tag">
<div id="instaTag">
<?php echo $view['wr_7'] ?>
</div></p>
<p> <button onclick="copy_to_clipboard()">copy</button>
</div>
<script>
function copy_to_clipboard() {
var copyText = document.getElementById('instaTag').textContent;
var textArea = document.createElement('textarea');
document.body.appendChild(textArea);
textArea.value = copyText;
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
alert('복사되었습니다.');
}</p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
3년 전
<button onclick="copy_to_clipboard('<?=$view['wr_7']?>')">copy</button></code></pre>
<pre>
<script>
function copy_to_clipboard(txt) {
var copyText = txt;
var textArea = document.createElement('textarea');
document.body.appendChild(textArea);
textArea.value = copyText;
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
alert('복사되었습니다.');
}
</script>
</pre>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
비타주리
3년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
textarea 를 생성시켰다가 카피가 끝나면 소멸시켜 버리네요.
저는 display none 과 block 을 오가는 식으로 하는데...
그래서 한수 배우고 갑니다.ㅋ