Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1153 댓글 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. [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기

    Date2018.10.19 CategoryDevelop Byhooni Views1234
    Read More
  2. [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태

    Date2018.10.19 CategoryDevelop Byhooni Views949
    Read More
  3. [ios] Swift 4 String, Date, DateFormatter 예제

    Date2018.10.18 CategoryDevelop Byhooni Views1378
    Read More
  4. Mac에서 Node.js 설치하기

    Date2018.09.28 CategorySystem/OS Byhooni Views4171
    Read More
  5. 서버 확장을 위한 두 가지 방법

    Date2018.08.29 CategorySystem/OS Byhooni Views2081
    Read More
  6. [ios] Requesting Location Permissions in iOS

    Date2018.08.18 CategoryDevelop Byhooni Views1583
    Read More
  7. [PHP] Mac OS에서 PHP 7 설치하기

    Date2018.05.11 CategoryDevelop Byhooni Views4861
    Read More
  8. [php] Connect to Firebase Console in Laravel

    Date2018.05.09 CategoryDevelop Byhooni Views3089
    Read More
  9. [api] 인스타그램 API Access_Token 발급 방법 (Instagram API)

    Date2018.04.05 CategoryDevelop Byhooni Views7501
    Read More
  10. [api] 인스타그램에서 최신 이미지 가져오기 (Using Instagram API)

    Date2018.04.05 CategoryDevelop Byhooni Views11807
    Read More
  11. [js] Click button copy to clipboard

    Date2018.04.05 CategoryDevelop Byhooni Views1153
    Read More
  12. [php] Laravel 4. twitter bootstrap 적용하기

    Date2018.04.05 CategoryDevelop Byhooni Views2523
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98