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()



    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"

<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. session 学习
  2. App Transport Security has blocked a cleartext
  3. Linux环境变量
  4. svn上想回滚代码怎么办?——svn merge 命令
  5. Lua标准库(转)
  6. leetcode majority number
  7. Bootstrap 源码解析(转)
  8. 关于Eclipse的常用快捷键
  9. Windows服务定时运行,判断当前时间是否在配置时间段内
  10. CSS三角形广告文字
  11. PHP XML Parser
  12. VS删除未使用的命名空间
  13. 【Java IO流】File类的使用
  14. CSharpGL(45)自制控件的思路
  15. SDK提交到CocoaPods
  16. Go学习——defer、panic
  17. Vue(小案例_vue+axios仿手机app)_首页(底部导航栏+轮播图+九宫格)
  18. Py 最全的常用正则表达式大全 ZZ
  19. h5需要的浏览器插件
  20. android -------- 打开本地浏览器或指定浏览器加载,打电话,打开第三方app

热门文章

  1. target属性用于返回最初触发事件的DOM元素。
  2. Map.containsKey(String key)
  3. Python接口测试实战1(上)- 接口测试理论
  4. 自己编写的:centos6.6上编译安装apache2.4+php5.6+mysql5.6【亲自】
  5. 判断浏览器是chrome,Opera,Safari,Mac
  6. tensorflow-gpu在win10下的安装
  7. 关于java学习中的一些易错点(基础篇)
  8. Netty源码分析第3章(客户端接入流程)----&gt;第1节: 初始化NioSockectChannelConfig
  9. 出现 org.springframework.beans.factory.BeanCreationException 异常的原因及解决方法
  10. python如何与以太坊交互并将区块链信息写入SQLite