Maison > Questions et réponses > le corps du texte
怪我咯2017-04-11 11:07:56
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.text-input{
border: none;
outline:medium;
box-shadow: none;
}
.copy-id:focus{
border: none;
}
</style>
</head>
<body>
<input readonly="readonly" class="copy-id text-input" type="text" value="12333333333"/>
<button class="copy">复制</button>
</body>
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript">
$('.copy').click(function () {
$('.copy-id').select();
document.execCommand("copy",false,null);
})
</script>
</html>
这是点击按钮,实现复制
PHPz2017-04-11 11:07:56
<input type="text" id="input">
<button onclick="copyFn()">点击</button>
<script>
function copyFn() {
var e = document.getElementById("input");
e.select();
document.execCommand("Copy");
}
</script>