Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 4403 댓글 0
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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
73 | Etc | WM미통기 - 10. 조건부확률 | hooni | 2015.04.20 | 2261 |
72 | Develop |
[ios] StoryBoard(xib) 없이 프로젝트 만들기
![]() |
hooni | 2015.02.12 | 2241 |
71 | Develop | [ios] 아이폰 앱 이름 및 버전 정보 | hooni | 2015.03.24 | 2214 |
70 | Develop |
[c#] BHO 한샘툴바랑 동현툴바..
![]() |
hooni | 2013.04.23 | 2208 |
69 | System/OS | [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우 | hooni | 2014.12.18 | 2206 |
68 | Develop | [ios] 로컬에 있는 html 실행하기 | hooni | 2015.02.10 | 2193 |
67 | Develop |
[js] AngularJS 란?
![]() |
hooni | 2015.11.26 | 2189 |
66 | Develop | [ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기 | hooni | 2015.02.10 | 2188 |
65 | Develop |
[ios] Xcode의 디버그 모드에서 콜스택
![]() |
hooni | 2015.01.03 | 2188 |
64 | Develop |
[ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export)
![]() |
hooni | 2015.01.03 | 2151 |
63 | System/OS | [mac] 패키지 매니저, MacPort | hooni | 2015.01.03 | 2147 |
62 | Develop |
[android] N-Puzzle 게임
![]() |
hooni | 2015.07.09 | 2145 |