<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.suoluomei.com/common/js2.0/npm/vant@2.2/lib/index.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>复制功能</title>
<style>
* {
padding: 0;
margin: 0;
}
[v-cloak] {
display: none !important;
}
#input {
width: 0;
height: 0;
position: fixed;
top: -0.02rem;
}
</style>
</head>
<body>
<div v-cloak id="Vue">
<span @click="cl(name)">{{name}}</span>
<textarea id="input"></textarea>
<button @click="copyText">copy</button>
</div>
</body>
<script src="https://cdn.suoluomei.com/common/js/jquery-2.1.4.min.js"></script>
<script src="https://cdn.suoluomei.com/common/js2.0/vue/v2.5.16/vue.js"></script>
<script src="https://cdn.suoluomei.com/common/js2.0/npm/vant@2.2/lib/vant.min.js"></script>
<script>
new Vue({
el: "#Vue",
data: {
name: "复制我成功没有",
copyshow: false
},
created() {
// let that = this
// $.ajax({
// type: "get", //请求方式
// async: false,
// url: "",
// data: {}, //传值给后台
// dataType: "json",
// success: function (res) {
// console.log(res)
//
// },
// });
},
methods: {
copyText() {
var input = document.getElementById("input");
input.value = this.name; // 修改文本框的内容
input.select(); // 选中文本
document.execCommand("copy"); // 执行浏览器复制命令
alert("复制成功");
}
}
})
</script>
<script>
(function (win, doc) {
if (!win.addEventListener) return;
var html = document.documentElement;
function setFont() {
var cliWidth = html.clientWidth;
if (cliWidth > 750) {
cliWidth = 750;
}
html.style.fontSize = 100 * (cliWidth / 750) + 'px';
}
win.addEventListener('resize', setFont, false)
doc.addEventListener('DOMContentLoaded', setFont, false)
})(window, document);
</script>
</html>
一键复制功能实现
最新推荐文章于 2024-09-29 22:49:06 发布