原生javascrip 复制功能

admin4年前前端技术1020

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


相关文章

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

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

通过jquery开发导航下来菜单

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

让javascrip函数内的局部变量能为全局使用的方法

<script type="text/javascript">   var mine;  function&nbs...

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

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

关于css的position参数自我领悟心得整理

relative :相对与最近的DOM定位   absolute :相对里面的绝对定位,跟relative 一起用,起到随心所欲定位的效果sticky :滚顶地位定位,用与鼠标滚动...

发表评论    

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