原生javascrip 复制功能

admin4年前前端技术991

兼容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中获取自定义标签data-id的值的几种常见方式

https://segmentfault.com/a/1190000005770912里面讲的很详尽了,在此就是总结一下做个笔记加深一下印象 。假如<div id="a&qu...

whatsapp浮动按钮

whatsapp浮动按钮

whatsapp浮动按钮whatsapp.zip...

jquery默认设置第一个类的css或者属性

var me=$("#cima>input");me.eq(0).css...

jquery中把字符串转成数字

jquery里把字符串转换为数字,用的是js,因为jquery本身就是用js封装编写的,比如我们在用jquery里的ajax来更新文章的阅读次数或人气的时候,就需要用到字符串转换为数字的功能了,先来看...

Navigate down the menu through jquery development

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

发表评论    

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