Develop
2018.04.05 09:57
[js] Click button copy to clipboard
Views 1288 Comment 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
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
841 | Develop | '2014 모바일 개발 트렌드' 발표자료입니다. | hooni | 2014.10.02 | 1134 |
840 | Develop | Aspect Oriented Programming in Objective-C | hooni | 2015.05.18 | 939 |
839 | Develop | DDay Memo 1.9.4 소스코드 | hooni | 2015.10.03 | 0 |
838 | Develop | GCM 사용하기 2 (단말에 GCM 구현하기) | hooni | 2013.07.06 | 23408 |
837 | Develop | GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기) 4 | hooni | 2013.07.06 | 25419 |
836 | Develop | git 브런치 배우기 (링크) | hooni | 2013.07.09 | 20696 |
835 | Develop | GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스 | hooni | 2014.10.14 | 1259 |
834 | Develop | How to Test SMTP AUTH using Telnet | hooni | 2018.04.05 | 1582 |
833 | Develop | JSON, BSON 변환 | hooni | 2013.04.23 | 11868 |
832 | Develop | Laravel 5 Failed opening required bootstrap/../vendor/autoload.php | hooni | 2018.01.24 | 1828 |
831 | Develop | Mac OS 에 Jenkins 설치하기 (Homebrew) 2 | hooni | 2017.03.15 | 8385 |
830 | Develop | macOS에 node, npm 설치하기 (homebrew) | hooni | 2021.11.06 | 1450 |