Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 4400 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Example no jQuery.


# JAVASCRIPT

function copyToClipboard(elementId) {

  // Create a "hidden" input
  var aux = document.createElement("input");

  // Assign it the value of the specified element
  aux.setAttribute("value", document.getElementById(elementId).innerHTML);

  // Append it to the body
  document.body.appendChild(aux);

  // Highlight its content
  aux.select();

  // Copy the highlighted text
  document.execCommand("copy");

  // Remove it from the body
  document.body.removeChild(aux);

}


# HTML

<p id="p1">P1: I am paragraph 1</p>
<p id="p2">P2: I am a second paragraph</p>
<button onclick="copyToClipboard('p1')">Copy P1</button>
<button onclick="copyToClipboard('p2')">Copy P2</button>
<br/><br/><input type="text" placeholder="Paste here for test" />



[출처] https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery




?

  1. [c] 연산자 우선순위.. ㅋㅋ

  2. [c] 지폰(gphone) 소스.. 수정(암호화)

  3. [asp] 기본 문법과 제어문

  4. [c] 신기한 atoi함수(www.game79.net)

  5. [c] 로또(Lotto) 번호 생성기

  6. [linux] crond 사용법.. ㅋㅋ

  7. [js] php의 number_format() 함수와 같은.. ㅋㅋ

  8. [js] 한글문서로 된 259가지 자바스크립트 예제파일

  9. [pdf] 포인터 문법 정리 (C pointer)

  10. [linux] 임베디드 리눅스 (embedded linux)

  11. [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스..

  12. [c] 문자열 라이브러리 최신버전

Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 99 Next
/ 99