Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 1279 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
141 | Develop | [switch] 시스코 스위치(catalyst 2950) telnet 설정 | hooni | 2013.04.23 | 11291 |
140 | Develop | [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 | hooni | 2013.04.23 | 11416 |
139 | System/OS | [switch] 시스코 카탈리스트(Cisco Catalyst) 기본 설정 | hooni | 2013.04.23 | 17567 |
138 | Develop | [ubuntu] 우분투 18.04에 PHP5 설치하기 | hooni | 2020.11.14 | 1084 |
137 | System/OS | [unix] AIX쉘 초기 파일 (.cshrc) | hooni | 2013.04.23 | 10345 |
136 | Develop | [unix] Java 애플릿용 HTML 자동 생성 | hooni | 2014.02.19 | 8262 |
135 | System/OS | [unix] SUN Solaris 싱글모드.. ㅡ,.ㅡ; | hooni | 2003.04.23 | 12049 |
134 | Develop | [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값) | hooni | 2013.04.23 | 14873 |
133 | Develop | [unix] 로그파일 정리 쉘스크립트 | hooni | 2014.02.19 | 10864 |
132 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 15001 |
131 | System/OS | [unix] 유닉스 csh에서 환경변수 등록 | hooni | 2003.04.23 | 11751 |
130 | Develop | [unix] 유닉스 명령에 메타문자 사용 | hooni | 2014.02.19 | 11296 |