Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 1160 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1137 | System/OS | [linux] 웹로그분석기(webalizer) 설치 & 팁 | hooni | 2003.04.23 | 14882 |
1136 | System/OS | [linux] 데스크탑환경(GNOME/KDE) 바꾸기.. | hooni | 2003.04.23 | 12101 |
1135 | System/OS | [linux] 센드메일 동적릴레이 설치 | hooni | 2003.04.23 | 15228 |
1134 | System/OS | HTTP 프로토콜 (브라우저와 웹서버 간의 통신) | hooni | 2003.04.23 | 48250 |
1133 | Database | [mysql] DB->Text, Text->DB 변환 | hooni | 2003.04.23 | 12126 |
1132 | System/OS | [windows] 패스워드를 잊어먹었을때.. | hooni | 2003.04.23 | 17294 |
1131 | System/OS | [bios] 시스템 부팅 도중 발생하는 비프음 | hooni | 2003.04.23 | 18158 |
1130 | System/OS | [unix] SUN Solaris 싱글모드.. ㅡ,.ㅡ; | hooni | 2003.04.23 | 11991 |
1129 | System/OS | [linux] ProFTPD 타임아웃 설정 | hooni | 2003.04.23 | 12851 |
1128 | Develop | [css] 스크롤바 안생기게 | hooni | 2003.04.23 | 9886 |
1127 | System/OS | [unix] 유닉스 csh에서 환경변수 등록 | hooni | 2003.04.23 | 11694 |
1126 | System/OS | [linux] 쉘 스크립트 (Shell Script) | hooni | 2003.04.23 | 12064 |