原生javascrip 复制功能

admin5年前前端技术1273

兼容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>


相关文章

Navigate down the menu through jquery development

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

通过jquery开发导航下来菜单

核心知识是用jquery的hover方法去实现,动画效果是slideDown与slideUp代码下载地址:点击下载...

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

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

分享与定时自动跳转

<!DOCTYPE html> <html> <head> <meta charset="utf-8">...

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

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

发表评论    

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