点击按钮将某个值复制到剪贴板的2个方法

 

 

方法一:

<textarea cols="20" rows="10" id="address" ref="address">用户定义的代码区域</textarea> 
<input type="button" onClick="copyUrl3()" value="点击复制" />

function copy() {
var Url2 = document.getElementById("biao1").innerText;
var oInput = document.createElement("input");
oInput.value = Url2;
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
oInput.className = "oInput";
oInput.style.display = "none";
alert("复制成功");
}

 

方法二:

html:

<textarea cols="20" rows="10" id="address" ref="address">用户定义的代码区域</textarea> 
<input type="button" onClick="copyUrl3()" value="点击复制" />
js:
copy() {
      this.$refs.address.select(); // 选择对象,  vue写法
  $("# address").select(); // 选择对象
      document.execCommand("Copy"); // 执行浏览器复制命令
    },

 

posted @ 2020-09-29 14:51  逸凨  阅读(534)  评论(0编辑  收藏  举报