클릭시 복사버튼 여러개

클릭시 복사버튼 여러개

QA

클릭시 복사버튼 여러개

답변 1

본문

게시판 리스트 페이지에 버튼 클릭하면 여분필드 wr_7의 텍스트가 복사대는 것을 구현하였습니다.

근데 리스트페이지다보니깐 버튼이 여러개인데 하나만.. 복사 기능이 되더라구요

혹시 버튼이 여러개라서 해당 여분필드 값이 각각 복사되게 어떻게 할수 있을까요?

 


<div class="tag">
                        <div id="instaTag">
                        <?php echo $view['wr_7'] ?>
                        </div>
                        <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('복사되었습니다.');
                        }

이 질문에 댓글 쓰기 :

답변 1


<button onclick="copy_to_clipboard('<?=$view['wr_7']?>')">copy</button>


<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>


답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 2,654
© SIRSOFT
현재 페이지 제일 처음으로