Home > Web Front-end > JS Tutorial > body text

JS implements copy function

高洛峰
Release: 2017-04-18 13:48:33
Original
1461 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template