A JS library that copies text to the Clipboard--clipboard.js__js

Source: Internet
Author: User

first, load the Clipboard.js file (a CDN I'm looking for online):

<script src= "Https://cdn.rawgit.com/zenorocha/clipboard.js/master/dist/clipboard.min.js" ></script>

Second, the HTML code:

<input type= "text" value= "Http://suo.im/8p5iq id=" Onlineimgurl "/> <button id=" Copylink "class="
btn Btn-primary "class=" btn dropdown-toggle "data-clipboard-target=" #onlineImgUrl "aria-label=" replication Success "> Copy link </ Button>

Note:
The Data-clipboard-target property Description duplicates the value content in #onlineimgurl, and the value in my input box is empty because it is written dynamically.
The Aria-label property is used to prompt for a copy of the result information, which I would eject if replication succeeds.
Finally, JS code like this:

    Copy link button
    var clipboard = new Clipboard ('. btn ');
    Clipboard.on (' Success ', function (e) {
        var msg = e.trigger.getattribute (' Aria-label ');
        Alert (msg);
    });

Look at the effect chart:

Input box is a bit ugly ... Because the input box seems to be unable to achieve the length of the adaptive eh, temporarily let it ugly (⊙o⊙) Ah. Oh, my picture URL is compressed.

* Learn more look here
https://clipboardjs.com/
http://9iphp.com/web/javascript/js-copy-library-clipboard-js.html*

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.