Develop
2018.04.05 09:57
[js] Click button copy to clipboard
Views 1305 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 | [ios] 아이폰용 앱 오픈 소스들 | hooni | 2013.04.23 | 469812 |
840 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 272453 |
839 | Develop | [ios] 언어, 지역, 국가 설정 가져오기 | hooni | 2014.05.12 | 272011 |
838 | Develop |
[ios] Start developing your navigation app for CarPlay without enrollment
![]() |
hooni | 2020.02.22 | 125440 |
837 | Develop |
[android] 만화 어플 소스코드
![]() |
hooni | 2013.04.23 | 92923 |
836 | Develop |
레고 마인드스톰 NXT 수도쿠, 큐브 소스코드..
20 ![]() |
hooni | 2013.04.23 | 81598 |
835 | Develop |
[c#] Hashtable <-> Json (dll 포함)
![]() |
hooni | 2013.04.23 | 80731 |
834 | Develop | [C#] MD5, SHA1 해시 & 인코딩 | hooni | 2013.04.23 | 77966 |
833 | Develop |
[android] 점심 해결 앱 소스 코드 ㅋㅋ
![]() |
hooni | 2013.04.23 | 76500 |
832 | Develop |
[json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드)
![]() |
hooni | 2013.04.23 | 72042 |
831 | Develop | [android] keytool을 사용하여 키스토어 생성 | hooni | 2013.04.23 | 69577 |
830 | Develop | [ios] Random Thoughts: Rand() vs. arc4random() | hooni | 2013.10.31 | 68123 |