Develop
2018.04.05 09:57
[js] Click button copy to clipboard
조회 수 1181 댓글 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
-
[oracle] SQL문 실행 방법 3가지
-
[css] z-index에 설정할 수 있는 최대값?
-
[js] jQuery plugin 요약
-
[linux] CentOS 터미널 언어 설정(한글/영어)
-
[linux] root 전환시 패스워드 없이 su 사용하기
-
[php] GregorianToJD(), JDToGregorian() 함수 내용
-
[php] 하루 전 날짜 쉽게 구하기.
-
[용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미
-
[js] AngularJS를 소개합니다.
-
iOS 에서 쓸만한 오프라인 구글지도 찾기
-
[ios] UIButton multi-line iOS7
-
[linux] iconv를 이용하여 euc-kr 문서를 utf-8로 대량으로 변환하기