Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 1286 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1041 | PPT | [ppt] 보안경제학 발표자료 | hooni | 2016.11.11 | 5 |
1040 | Develop | [Android Error] The number of method references in a .dex file cannot exceed 64K | hooni | 2016.11.10 | 887 |
1039 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1604 |
1038 | Develop | [android] 초간단 얼럿 (AlertDialog) | hooni | 2016.10.21 | 933 |
1037 | Develop | [android] dp, px 서로 변환 | hooni | 2016.10.21 | 3496 |
1036 | Develop | [matlab] ZigZag-Scanning (2-D Array) | hooni | 2016.10.15 | 2109 |
1035 | System/OS | [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 | hooni | 2016.10.03 | 1165 |
1034 | System/OS | [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 | hooni | 2016.10.03 | 1734 |
1033 | Develop | [matlab] 정보은닉 스테가노그래피(Steganography) 수업 | hooni | 2016.10.03 | 784 |
1032 | Develop | [c] RSA 암호화 구현(gmp 라이브러리 활용) | hooni | 2016.10.03 | 1008 |
1031 | Develop | [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 | hooni | 2016.10.03 | 1437 |
1030 | Develop | [c] 셀프 넘버(Self Number) 구하기 1 | hooni | 2016.09.09 | 2378 |