clipboard.js melaksanakan fungsi menyalin kandungan penyemak imbas ke papan keratan sistem dalam JavaScript tulen (tiada Flash). Boleh digunakan dalam pelayar dan persekitaran Node. Sokong Chrome 42, Firefox 41, IE 9, Opera 29
Tapak web rasmi: https://github.com/zenorocha/clipboard.js
Muat turun perisian: http://www.jb51.net/jiaoben/385604.html
Penggunaan rasmi: https://zenorocha.github.io/clipboard.js/#example-text
Kod sampel:
Contoh rasmi satu:
Tunjuk cara dalam talian: http://demo.jb51.net/js/2015/clipboard/
<script src="clipboard.min.js"></script> <textarea id="bar" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">脚本之家是国内专业的网站建设资源、脚本编程学习类网站,提供asp、php、asp.net、javascript、jquery、vbscript、dos批处理、网页制作、网络编程、网站建设等编程资料。</textarea> <!-- Trigger --> <button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar"> Cut to clipboard </button> <script> var clipboard = new Clipboard('.btn'); clipboard.on('success', function(e) { console.info('Action:', e.action); console.info('Text:', e.text); console.info('Trigger:', e.trigger); alert("复制成功"); e.clearSelection(); }); clipboard.on('error', function(e) { console.error('Action:', e.action); console.error('Trigger:', e.trigger); }); </script>
Contoh rasmi dua:
<script src="dist/clipboard.min.js"></script> <button class="btn"> <script type="text/javascript"> var clipboard = new Clipboard('.btn'); clipboard.on('success', function(e) { console.info('Action:', e.action); console.info('Text:', e.text); console.info('Trigger:', e.trigger); e.clearSelection(); }); clipboard.on('error', function(e) { console.error('Action:', e.action); console.error('Trigger:', e.trigger); }); </script>