Home >Web Front-end >JS Tutorial >JS implements copy function

JS implements copy function

高洛峰
高洛峰Original
2017-04-18 13:48:331475browse

This article mainly introduces examples of JS realizing the copy function, which has a very good reference value. Let’s take a look at it with the editor.

Rendering:

JS implements copy function

The code is as follows:

<!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=&#39;http://libs.baidu.com/jquery/2.0.0/jquery.js&#39;></script>
 <script>
  $(document).ready(function(){
  $(&#39;button&#39;).click(function(){
  $(&#39;input&#39;).trigger(&#39;select&#39;);
  document.execCommand(&#39;copy&#39;);
  alert(&#39;复制成功&#39;)
  })
  })
 </script>
</body>
</html>

For more articles related to JS implementation of copy function, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:js drop-down menu effectNext article:js drop-down menu effect