<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8"> <title>constructor-nodelist</title> </head> <body> <!-- 1. Define some markup --> <buttondata-clipboard-text='静态文本1'>Copy</button> <buttondata-clipboard-text='静态文本2'>Copy</button> <buttondata-clipboard-text='静态文本3'>Copy</button> <!-- 2. Include library --> <scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script> <!-- 3. Instantiate clipboard by passing a list of HTML elements --> <script> //使用标签选择器获取列表 var btns = document.querySelectorAll('button'); var clipboard = newClipboardJS(btns); clipboard.on('success', function (e) { alert("复制成功"); }); clipboard.on('error', function (e) { alert("复制失败"); }); </script> </body> </html>