Javascript 数据表复制到剪贴板干涉
我正在使用Javascript 数据表复制到剪贴板干涉,javascript,datatables,Javascript,Datatables,我正在使用数据表,客户端处理和按钮扩展 在站点上,我显示一个表,我需要一个函数将div中包含的一些文本复制到剪贴板。我使用此代码的目的是: var div = document.createRange(); div.setStart(container, 0); div.setEndAfter(container) ; window.getSelection().addRange(div); document.execCommand("Copy"); 这一切都很正常,除非在使用“复制到剪贴板”
数据表
,客户端处理和按钮扩展
在站点上,我显示一个表,我需要一个函数将div中包含的一些文本复制到剪贴板。我使用此代码的目的是:
var div = document.createRange();
div.setStart(container, 0);
div.setEndAfter(container) ;
window.getSelection().addRange(div);
document.execCommand("Copy");
这一切都很正常,除非在使用“复制到剪贴板”功能之前在datatable中选择一个条目。当我在表中选择一个条目,然后使用“复制到剪贴板”功能时,它不仅会从容器中复制所需的文本,还会复制datatables div内容
我想这可能是我的js函数和dataTables按钮扩展的copy to clipboard函数之间的干扰,后者似乎提供了copy to clipboard函数
对此有何想法?事实证明,dataTables在选择表中的条目时会创建一个范围。 所以我检查一个范围是否已经存在,如果已经存在-我删除该范围并继续创建我自己的范围 这对我来说很好。如果有人感兴趣,下面是代码片段:
s = window.getSelection();
if(s.rangeCount > 0) {
for(var i = 0; i < s.rangeCount; i++) {
s.removeRange(s.getRangeAt(i));
}
var div = document.createRange();
div.setStart(container, 0);
div.setEndAfter(container) ;
window.getSelection().addRange(div);
document.execCommand("Copy");
}
s=window.getSelection();
如果(s.rangeCount>0){
对于(变量i=0;i