Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 4403 댓글 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




?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
243 Develop [js] 양원님이 공유해 주신 유료(5$란다ㅋ) 자료 ㅋㅋ secret hooni 2013.04.23 7948
242 Develop [js] 스타크래프트(starcraft).. file hooni 2013.04.23 7947
241 Develop [js] 윈도우 시작버튼처럼 나오는 메뉴 file hooni 2013.04.23 7945
240 Develop [c++] 트리컨트롤 예제1 ㅋㅋ file hooni 2013.04.23 7941
239 Develop [c] 소켓의 세가지 동작모드 hooni 2003.04.23 7938
238 Develop [js] 가운데 새창 뜨는 함수와 이벤트 hooni 2003.04.23 7938
237 Develop [c] 메세지 프로그램 (Server - Agent - Client) file hooni 2013.04.23 7927
236 Develop [c] 단기과정[01/14] 파일 입출력 file hooni 2003.04.23 7921
235 Develop [php] 메모장 - 웅지학원 ([c] mysql 백업프로그램 포함) file hooni 2003.04.23 7921
234 Develop [c] 소켓주소 구조체에 대해.. hooni 2003.04.23 7917
233 Develop [c++] 트리컨트롤 스텝 2 예제.. file hooni 2013.04.23 7898
232 Develop [c] 시간 계산 하는 프로그램 소스코드 file hooni 2003.04.23 7895
Board Pagination Prev 1 ... 46 47 48 49 50 51 52 53 54 55 ... 71 Next
/ 71