“Salin ke Clipboard JQuery” Kode Jawaban

Teks JavaScript ke clipboard

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

Salin teks ke clipboard jQuery

function copyToClipboard(element) {
 var $temp = $("<input>");
 $("body").append($temp);
 $temp.val($(element).html()).select();
 document.execCommand("copy");
 $temp.remove();
}
Witness

cara menyalin teks di clipboard di js

<html>
  <input type="text" value="Hello world"(Can be of your choice) id="myInput"(id is the name of the text, you can change it later)
<button onclick="Hello()">Copy Text</button>

<script>
  function Hello() {
  var copyText = document.getElementById('myInput')
  copyText.select();
  document.execCommand('copy')
  console.log('Copied Text')
}
</script>
Upset Unicorn

Salin JavaScript ke clipboard

var copyTextarea = document.getElementById("someTextAreaToCopy");
copyTextarea.select(); //select the text area
document.execCommand("copy"); //copy to clipboard
Grepper

Salin teks pada tombol klik di jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<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" />
Cloudy Cottonmouth

Salin ke Clipboard JQuery

function copy(elem, type = 'input') {

  let text = '';
  
  //define the target text;
  if (type === 'input')
    text = $(elem).val();
  else 
    text = $(elem).text();

  //append input element to body to store target text
  var temp = $("<input>");
  $("body").append(temp);

  temp.val(text).select();   //select text to make it able executable
  document.execCommand("copy"); //run the copy command.

  temp.remove(); // remove input element from DOM after Execute copy command.

  // add effect to element to user notice copy execution.
  let notify =  $('<i class="fas fa-keyboard fa-2x text-info bg-light">Copied!!</i>');
  $(elem).closest('div').find('.fas').prepend(notify); 
  notify.css('display', 'block')
  notify.fadeOut(2000); 

}
hansal

Jawaban yang mirip dengan “Salin ke Clipboard JQuery”

Pertanyaan yang mirip dengan “Salin ke Clipboard JQuery”

Lebih banyak jawaban terkait untuk “Salin ke Clipboard JQuery” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya