clipboard.js牛逼的方法复制文本到剪贴板

A modern approach to copy text to clipboard

No Flash. No dependencies. Just 2kb

Why

Copying text to the clipboard shouldn’t be hard. It shouldn’t require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn’t depend on Flash or any bloated framework.

That’s why clipboard.js exists.

Install

If you’re not into package management, just download a ZIP file.

Setup

First, include the script located on the dist folder.

<script src=”dist/clipboard.min.js”></script>

Now, you need to instantiate it using a DOM selector. This selector corresponds to the trigger element(s), for example:

<button class=”btn”>.

new Clipboard(‘.btn’);

Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.

转载请注明出处:前端开发 » clipboard.js牛逼的方法复制文本到剪贴板

赞 (2)
分享到: 更多

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址