Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 1155 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
9 | Algorithm | OCB5 Injection 앗싸뵹! ㅋㅋ | hooni | 2014.07.01 | 781 |
8 | Algorithm | 러시아 페인트공 알고리즘에 대해.. | hooni | 2013.04.23 | 22881 |
7 | Algorithm | 디피헬만(Diffie-Hellman) 초간단 개념.. | hooni | 2013.04.23 | 81004 |
6 | Algorithm | 암호 알고리즘 및 프로토콜의 이해.. | hooni | 2013.04.23 | 17194 |
5 | Algorithm | Polynomial time 이란? ㅋㅋ | hooni | 2013.04.23 | 22248 |
4 | Algorithm | [security] 블럭 암호에 대해서.. | hooni | 2013.04.23 | 17104 |
3 | Algorithm | 스터디 자료, 암호화에 대해서.. 나중에 볼 ppt.. | hooni | 2013.04.23 | 13356 |
2 | Algorithm | [security] RSA 암호화 설명과 예.. | hooni | 2013.04.23 | 16602 |
1 | Algorithm | [algorithm] Greedy (탐욕 기법) | hooni | 2003.04.23 | 15096 |