Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1181 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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




?

  1. [oracle] SQL문 실행 방법 3가지

    Date2013.12.19 CategoryDatabase Byhooni Views12126
    Read More
  2. [css] z-index에 설정할 수 있는 최대값?

    Date2013.12.20 CategoryDevelop Byhooni Views14720
    Read More
  3. [js] jQuery plugin 요약

    Date2013.12.20 CategoryDevelop Byhooni Views10703
    Read More
  4. [linux] CentOS 터미널 언어 설정(한글/영어)

    Date2013.12.22 CategorySystem/OS Byhooni Views18517
    Read More
  5. [linux] root 전환시 패스워드 없이 su 사용하기

    Date2013.12.22 CategorySystem/OS Byhooni Views12688
    Read More
  6. [php] GregorianToJD(), JDToGregorian() 함수 내용

    Date2013.12.25 CategoryDevelop Byhooni Views10596
    Read More
  7. [php] 하루 전 날짜 쉽게 구하기.

    Date2013.12.25 CategoryDevelop Byhooni Views12219
    Read More
  8. [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미

    Date2014.01.02 CategoryEtc Byhooni Views41963
    Read More
  9. [js] AngularJS를 소개합니다.

    Date2014.01.06 CategoryDevelop Byhooni Views13017
    Read More
  10. iOS 에서 쓸만한 오프라인 구글지도 찾기

    Date2014.01.06 CategoryEtc Byhooni Views16039
    Read More
  11. [ios] UIButton multi-line iOS7

    Date2014.01.09 CategoryDevelop Byhooni Views11437
    Read More
  12. [linux] iconv를 이용하여 euc-kr 문서를 utf-8로 대량으로 변환하기

    Date2014.01.09 CategorySystem/OS Byhooni Views12221
    Read More
Board Pagination Prev 1 ... 65 66 67 68 69 70 71 72 73 74 ... 98 Next
/ 98