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




?

  1. Aspect Oriented Programming in Objective-C

  2. [c#] 툴바 소스.. 개인적으로 만드는거..

  3. [ios] 배경에 Gradient 적용하기 (CAGradientLayer)

  4. [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기

  5. [ios] GMT Date와 Local Date 변환하기

  6. [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define

  7. [ios] 카테고리 확장 메소드를 찾지 못하는 경우

  8. [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)

  9. [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #2 (client)

  10. [android] SQLiteOpenHelper를 이용한 DBManager

  11. [ios] 설정에서 푸시 알림(APNS) on/off 상태 확인

  12. [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기)

Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 71 Next
/ 71