一、js按钮点击按钮复制指定内容
例如电商一键复制收货地址。
1.html代码(样式根据自己需求修改)
代码如下(示例):
<div class="copyText">
<span>蔡文姬</span>
<span style="margin:0 24px">10086 </span>
<span>王者峡谷游走路超级奶妈</span>
</div>
<el-button type="text" @click="copyHandler" style="margin:0 24px">复制信息</el-button>
2.js点击事件
代码如下(示例):
copyHandler() {
const input = document.createElement("input");
const copyText = document.querySelector(".copyText");
input.value = copyText.innerText;
document.body.appendChild(input);
input.select();
document.execCommand("Copy");
document.body.removeChild(input);
this.$message.success(copyText.innerText);
},
3.点击复制按钮 效果图如下
总结
提示:以上内容仅供参考;如有不正望指出。