data-clipboard-text is not working while using clipboard.js

前端 未结 1 386
Happy的楠姐
Happy的楠姐 2021-01-24 01:54

I have a simple structure to test clipboard.js but it\'s not working.

I used in a simple file because it was not working in the project too:



        
相关标签:
1条回答
  • 2021-01-24 02:32

    you need to instantiate it by passing a DOM selector, HTML element, or list of HTML elements.

    new ClipboardJS('.btn');
    

    https://clipboardjs.com/#setup

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    
    <body>
      <button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
        Copy to clipboard
    </button>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script>
      <script>
        new ClipboardJS('.btn');
      </script>
    </body>
    
    </html>

    0 讨论(0)
提交回复
热议问题