javascript - js实现ctrl + c 的复制功能?
本文介绍了javascript - js实现ctrl + c 的复制功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
js怎样实现ctrl + c 的复制功能?
解决方案
<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>
这是点击按钮,实现复制
这篇关于javascript - js实现ctrl + c 的复制功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文