1. 程式人生 > >將input框中的值複製到瀏覽器的剪下板中

將input框中的值複製到瀏覽器的剪下板中

<input  type="hidden"  id="qrcodeUrl" value="https://www.baidu.com">


<button class="button-code button-copy">複製連結</button>
$(".button-copy").on("click", function(){
    var qrcodeUrl = $("#qrcodeUrl").val();
    var oInput = document.createElement('input');
    oInput.value = qrcodeUrl;
    document.body.appendChild(oInput);
    oInput.select(); // 選擇物件
    document.execCommand("Copy"); // 執行瀏覽器複製命令
    oInput.className = 'oInput';
    alert('複製成功');

});