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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
345 | Database | [oracle] SQL문 실행 방법 3가지 | hooni | 2013.12.19 | 12126 |
344 | Develop | [css] z-index에 설정할 수 있는 최대값? | hooni | 2013.12.20 | 14720 |
343 | Develop | [js] jQuery plugin 요약 | hooni | 2013.12.20 | 10703 |
342 | System/OS | [linux] CentOS 터미널 언어 설정(한글/영어) | hooni | 2013.12.22 | 18517 |
341 | System/OS | [linux] root 전환시 패스워드 없이 su 사용하기 | hooni | 2013.12.22 | 12688 |
340 | Develop | [php] GregorianToJD(), JDToGregorian() 함수 내용 | hooni | 2013.12.25 | 10596 |
339 | Develop | [php] 하루 전 날짜 쉽게 구하기. | hooni | 2013.12.25 | 12219 |
338 | Etc | [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미 | hooni | 2014.01.02 | 41963 |
337 | Develop | [js] AngularJS를 소개합니다. | hooni | 2014.01.06 | 13017 |
336 | Etc | iOS 에서 쓸만한 오프라인 구글지도 찾기 | hooni | 2014.01.06 | 16039 |
335 | Develop | [ios] UIButton multi-line iOS7 | hooni | 2014.01.09 | 11437 |
334 | System/OS | [linux] iconv를 이용하여 euc-kr 문서를 utf-8로 대량으로 변환하기 | hooni | 2014.01.09 | 12221 |