将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('复制成功');

});

猜你喜欢

转载自blog.csdn.net/echo_hello_world/article/details/82761331