“JavaScript Klicken Sie Klicken, um zu kopieren” Code-Antworten

JavaScript -Text in die Zwischenablage

function copyToClipboard(text) {
   const elem = document.createElement('textarea');
   elem.value = text;
   document.body.appendChild(elem);
   elem.select();
   document.execCommand('copy');
   document.body.removeChild(elem);
}
Dennis "Awesome" Rosenbaum

JavaScript Klicken Sie Klicken, um zu kopieren

function copyToClipboard(value) {
  navigator.clipboard.writeText(value)
}
Payer of the Iron Price

JavaScript How-Do-i-Copy-to-the-Clipboard-in-JavaScript

function copyToClipboard(text) {
  var input = document.body.appendChild(document.createElement("input"));
  input.value = text;
  input.focus();
  input.select();
  document.execCommand('copy');
  input.parentNode.removeChild(input);
}
TC5550

So aktivieren Sie die Funktion mit JS auf die Funktion des Kopierens auf die Kopie

var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.focus();
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});

////html code below
<p>
  <button class="js-textareacopybtn" style="vertical-align:top;">Copy Textarea</button>
  <textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>
JDBC

Kopieren Sie den Text Onclick

const span = document.querySelector("span");

span.onclick = function() {
  document.execCommand("copy");
}

span.addEventListener("copy", function(event) {
  event.preventDefault();
  if (event.clipboardData) {
    event.clipboardData.setData("text/plain", span.textContent);
    console.log(event.clipboardData.getData("text"))
  }
});
Damon

JS Kopie Absatz Onclick

var copy = document.querySelectorAll(".copy"); 

for (const copied of copy) { 
  copied.onclick = function() { 
    document.execCommand("copy"); 
  };  
  copied.addEventListener("copy", function(event) { 
    event.preventDefault(); 
    if (event.clipboardData) { 
      event.clipboardData.setData("text/plain", copied.textContent);
      console.log(event.clipboardData.getData("text"))
    };
  });
};
Borma

Ähnliche Antworten wie “JavaScript Klicken Sie Klicken, um zu kopieren”

Fragen ähnlich wie “JavaScript Klicken Sie Klicken, um zu kopieren”

Weitere verwandte Antworten zu “JavaScript Klicken Sie Klicken, um zu kopieren” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen