标签:paste ocs log const evel || dde aaaaa boa
//设置剪切板内容
document.addEventListener("copy",function () {
if (event.clipboardData || event.originalEvent) {
var clipboardData = (event.clipboardData || event.originalEvent.clipboardData);
const selection = "AAAAA";
clipboardData.setData(‘text/plain‘, selection.toString());
event.preventDefault();
}
});
注意:clipboardData.setData("参数1","参数2") 参数1的值要对应http的content-type的类型,如果没有设置参数1的话有可能会报错
//获取剪切板的内容
document.addEventListener("paste", function () {
if (event.clipboardData || event.originalEvent) {
var clipboardData = (event.clipboardData || window.clipboardData);
var val = clipboardData.getData(‘text‘);
console.log(val);
event.preventDefault();
}
});
可以参考这个:https://developer.mozilla.org/zh-CN/docs/Web/API/ClipboardEvent/clipboardData
标签:paste ocs log const evel || dde aaaaa boa
原文地址:https://www.cnblogs.com/zhanping/p/13226193.html