我是靠谱客的博主 神勇小蜜蜂,这篇文章主要介绍js & click copy to clipboardjs & click copy to clipboard,现在分享给大家,希望可以做个参考。

js & click copy to clipboard

https://www.cnblogs.com/xgqfrms/p/9999061.html
https://www.cnblogs.com/xgqfrms/p/10189199.html
https://www.cnblogs.com/xgqfrms/p/10109703.html

https://www.w3schools.com/howto/howto_js_copy_clipboard.asp

vanilla js

  1. window.copy only for Chrome Console

  2. document.execCommand("copy") & copyText.select()

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
clickGetNewsId() { let that = this; let newsID = document.querySelector(`[data-uid="newsId"]`); if (newsID) { let result = that.commonHandle.newsId || ``; let input = newsID.lastElementChild; input.addEventListener(`click`, (e) => { // console.log(`e.target =`, e.target); // console.log(`e.target.dataset =`, e.target.dataset); // console.log(`e.target.value =`, e.target.value); // that.clickCopyText(input); // this.clickCopyText(); 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 { // } // if (newsID) { // result = newsID.lastElementChild.value; // // result = that.commonHandle.newsId; // } }, clickCopyText(input) { let that = this; let result = that.commonHandle.newsId || ``; // console.log(`click copy!`, result); // console.log(`window.copy`, window.copy); // undefined try { if (input) { input.select(); if (result) { document.execCommand("copy"); that.$hMessage.sucess(`资讯 ID, 复制成功!`); } else { that.$hMessage.info(`资讯 ID 为空, 无法复制!`); } } } catch (err) { console.log(`click copy error =`, err); that.$hMessage.error(`你的浏览器太古老了,暂时不支持点击复制的功能!`); } // try { // if (window.copy) { // if (result) { // console.log(`window.copy!`); // window.copy(result); // that.$hMessage.sucess(`资讯 ID, 复制成功!`); // } else { // that.$hMessage.info(`资讯 ID 为空, 无法复制!`); // } // } // } catch (err) { // console.log(`click copy error =`, err); // that.$hMessage.error(`你的浏览器太古老了,暂时不支持点击复制的功能!`); // } return result; },

vue

  1. input must be :disabled="false"
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<h-row class-name="common-handle-padding"> <h-col span="24"> <span class="audit-common-lable">资讯 ID</span> <h-input aria-placeholder="资讯 ID" placeholder="请输入资讯 ID" style="width: 80%" ref="newsId" data-uid="newsId" v-model="commonHandle.newsId" @on-change="onChangeInput(`newsId`)" @on-enter="onChangeInput(`newsId`)" :readonly="true" :disabled="false"> </h-input> </h-col> </h-row>

https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
https://stackoverflow.com/questions/19606221/copy-a-text-when-a-link-or-button-is-clicked
https://stackoverflow.com/questions/37381640/tooltips-highlight-animation-with-clipboard-js-click

http://codetheory.in/javascript-copy-to-clipboard-without-flash-using-cut-and-copy-commands-with-document-execcommand/

https://davidwalsh.name/clipboard

libs

https://clipboardjs.com/

复制代码
1

转载于:https://www.cnblogs.com/xgqfrms/p/10290111.html

最后

以上就是神勇小蜜蜂最近收集整理的关于js & click copy to clipboardjs & click copy to clipboard的全部内容,更多相关js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部