原生javascrip 复制功能

admin5年前前端技术1384

兼容chrome FIrfox IE 

下载地址

000.zip


代码如下:

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <title>My sql</title>
</head>
<body>
<style type="text/css">
#newtext {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;}
</style>
<span id="wenzi">I love you!!!</span>
<input id="newtext" value="">
<button type="button"  onclick="fuzhi()">Copy Link</button>
 
<script type="text/javascript">
function fuzhi(){
var newtext=document.getElementById("newtext");
var wenzi=document.getElementById("wenzi").innerText;
newtext.value=wenzi;
newtext.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
alert("Copy Successfull");
}
  </script>
</body>
</html>


相关文章

ubbedit实现遍历绝对目录绑定cookie查询以前上传的图片

ubbedit实现遍历绝对目录绑定cookie查询以前上传的图片

设置cookie ,$user_id=$_COOKIE["user_email"];设置path   , $path =  "/"...

Navigate down the menu through jquery development

The core knowledge is to use jquery's hover method to achieve, The animation effe...

通过jQuery Ajax使用FormData对象上传文件,实现uedito文本编辑器独立上传单个图片的功能

FormData对象,是可以使用一系列的键值对来模拟一个完整的表单,然后使用XMLHttpRequest发送这个"表单"。在 Mozilla Developer ...

js与jquery自动触发a链接的方法

自动触发a链接的方法如下:1.<body >  <a  href="http://www.shengmake.net"&...

jquery如何获取div里面value的值以及原生写法

jquery写法$(this).attr("value")原生写法var value = document.getElementById(""+id+"...

让TD 与div自动换行的css方法

word-wrap: break-word;  word-break: break-all; white-space: normal;...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。