“JQuery Copy to Schowbard” Kod odpowiedzi

Skopiuj tekst do JQuery Schoward

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

Kopia JavaScript do schowka

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

Skopiuj tekst na przycisk Kliknij 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

Skopiuj do Schowniczki JQuery JavaScript

<div id="copyText" style="display:none"></div>
<div id="copyTextInput" onclick="copyToClipboard($('#copyTextInput').text())">hello!</div>

<script>
    function copyToClipboard(text) {
        var temp = $("<input>");
        $("body").append(temp);
        temp.val(text).select();
        document.execCommand("copy");
        temp.remove();
        $("#copyText").css("display","block");
        $("#copyText").html('text Copied!!!').fadeOut(2000);
    }
</script>
Amin Arjmand

JQuery Copy to Schowbard

document.execCommand("copy");
Kaotik

Skopiuj do schowka

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

Odpowiedzi podobne do “JQuery Copy to Schowbard”

Pytania podobne do “JQuery Copy to Schowbard”

Więcej pokrewnych odpowiedzi na “JQuery Copy to Schowbard” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu