原生javascrip 复制功能

admin5年前前端技术1080

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

当div里的height:atuo不能实现高度自适应的时候

当div里的height:atuo不能实现高度自适应的时候添加如下代码就可以实现overflow:hidden;/*解决了flat left 漂浮,让高度不可控的问题*/...

webpack全局安装了,使用命令时却提示安装脚手架

全局安装了webpack ,使用webpack的时候,却有如下的提示One CLI for webpack must be installe...

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

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

H5页面移动端双击屏幕禁止页面放大

在meta标签中加入user-scalable=no属性...

whatsapp浮动按钮

whatsapp浮动按钮

whatsapp浮动按钮whatsapp.zip...

发表评论    

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