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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
669 | Develop | [ios] iOS에서 디바이스 종류 알아오기 | hooni | 2014.05.24 | 3658 |
668 | Develop | [ios] iphone SetDeviceOrientation 화면 강제 회전 | hooni | 2013.11.20 | 18470 |
667 | Develop | [ios] libxml/tree.h file not found | hooni | 2013.08.08 | 18710 |
666 | Develop | [ios] Locale Identifiers | hooni | 2018.11.29 | 1634 |
665 | Develop | [ios] NavigationController 에서 왼쪽(back) 버튼 후킹하기 | hooni | 2015.10.23 | 1191 |
664 | Develop | [ios] None IB vs. StoryBoard 샘플 소스 | hooni | 2013.09.06 | 16938 |
663 | Develop | [ios] NSData to NSString (NSString to NSData) | hooni | 2015.07.21 | 644 |
662 | Develop | [ios] NSData 클래스에 대해 (NSData <-> char*) | hooni | 2013.04.23 | 26573 |
661 | Develop | [ios] NSMutableString 문자열 패턴 교환 | hooni | 2013.04.23 | 28994 |
660 | Develop | [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ | hooni | 2015.06.26 | 659 |
659 | Develop | [ios] NSString URL Encode/Decode (인코딩/디코딩) | hooni | 2014.05.02 | 3425 |
658 | Develop | [ios] NSString 간단한 정규식 사용법 | hooni | 2014.01.28 | 18223 |