Home >Web Front-end >JS Tutorial >JS implements copy function
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:
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='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>
For more articles related to JS implementation of copy function, please pay attention to the PHP Chinese website!