🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# clipboard复制 <https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js> `npm install clipboard --save` ``` <pre class="calibre16">``` <span class="token"><</span>input id<span class="token">=</span><span class="token4">"foo"</span> value<span class="token">=</span><span class="token4">"被复制内容"</span><span class="token">></span> <span class="token"><</span>button class<span class="token">=</span><span class="token4">"btn"</span> data<span class="token">-</span>clipboard<span class="token">-</span>target<span class="token">=</span><span class="token4">"#foo"</span><span class="token">></span> 复制 <span class="token"><</span><span class="token">/</span>button<span class="token">></span> <span class="token"><</span>button class<span class="token">=</span><span class="token4">"btn"</span> data<span class="token">-</span>clipboard<span class="token">-</span>text<span class="token">=</span><span class="token4">"内容"</span><span class="token">></span> 复制 <span class="token"><</span><span class="token">/</span>button<span class="token">></span> var clipboard <span class="token">=</span> <span class="token5">new</span> <span class="token1">clipboard</span><span class="token2">(</span><span class="token4">'.btn'</span><span class="token2">)</span><span class="token2">;</span> clipboard<span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'success'</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>e<span class="token2">)</span> <span class="token2">{</span> <span class="token1">alert</span><span class="token2">(</span><span class="token4">"复制成功"</span><span class="token2">)</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> ``` ```