首页 > 编程 > JavaScript > 正文

JS实现复制功能

2019-11-19 17:22:50
字体:
来源:转载
供稿:网友

效果图:

代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><title>JS复制功能</title><link href="" rel=" rel="external nofollow" stylesheet"><style> *{ margin:0; padding:0; } input{ border:1px solid #ccc; padding: 5px; width: 200px; } button{ height:32px; }</style></head><body> <input type="text"placeholder="里面输入文字"> <button type="button">点击复制</button> <script type="text/javascript" src='http://libs.baidu.com/jquery/2.0.0/jquery.js'></script> <script>  $(document).ready(function(){  $('button').click(function(){  $('input').trigger('select');  document.execCommand('copy');  alert('复制成功')  })  }) </script></body></html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持武林网!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表