js implements one-click copy

Import clipboard.js

Use as follows

<script>
    copyFn = function() {
            var clipboard = new Clipboard('.copy-btn', {
                text: function(trigger) {
                    return $('.copy-txt').text();
                }
            });
            clipboard.on('success', function() {
                alert( ' Copy successfully! ' );
            });
            clipboard.on('error', function(e) {
                alert( ' Please manually select the invitation code to copy! ' );
            });
        }
     copyFn ();
</script>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325246874&siteId=291194637