xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Clipboard API

Clipboard API

click copy



click copy demo



    clickGetNewsLink(data_ref = `newsLink`) {
        let that = this;
        let newsLink = document.querySelector(`[data-uid="${data_ref}"]`);
        // let newsLink = document.querySelector(`[data-uid="newsLink"]`);
        if (newsLink) {
            let result = that.commonHandle.newsLink || ``;
            let input = newsLink.lastElementChild;
            input.addEventListener(`click`, (e) => {
                try {
                    if (result) {
                        input.select();
                        document.execCommand("copy");
                        that.$hMessage.success(`资讯链接地址, 复制成功!`);
                    } else {
                        that.$hMessage.info(`资讯链接地址, 无法复制!`);
                    }
                } catch (err) {
                    console.log(`click copy error =`, err);
                    that.$hMessage.error(`你的浏览器太古老了,暂时不支持点击复制的功能!`);
                }
            });
        }
    },
    clickGetNewsId() {
        let that = this;
        let newsID = document.querySelector(`[data-uid="newsId"]`);
        if (newsID) {
            let result = that.commonHandle.newsId || ``;
            let input = newsID.lastElementChild;
            // input.style = `width: 100%; min-width: 217px; color: #000; cursor: pointer !important;`;
            input.addEventListener(`click`, (e) => {
                try {
                    if (result) {
                        input.select();
                        document.execCommand("copy");
                        that.$hMessage.success(`资讯 ID, 复制成功!`);
                    } else {
                        that.$hMessage.info(`资讯 ID 为空, 无法复制!`);
                    }
                } catch (err) {
                    console.log(`click copy error =`, err);
                    that.$hMessage.error(`你的浏览器太古老了,暂时不支持点击复制的功能!`);
                }
            });
        } else {
            //
        }
    },

refs

https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API

https://clipboardjs.com/



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-02-08 11:31  xgqfrms  阅读(113)  评论(5编辑  收藏  举报