微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cocos Creator JS web平台复制粘贴代码亲测可用

Cocos Creator JS web平台复制粘贴代码(亲测可用)

1
webcopyString: function(str){ 2 var input = str; 3 const el = document.createElement(‘textarea‘); 4 el.value = input; 5 el.setAttribute(‘readonly‘,‘‘); 6 el.style.contain = ‘strict‘; 7 el.style.position = ‘absolute‘; 8 el.style.left = ‘-9999px‘; 9 el.style.fontSize = ‘12pt‘; // Prevent zooming on iOS 10 11 const selection = getSelection(); 12 var originalRange = false; 13 if (selection.rangeCount > 0) { 14 originalRange = selection.getRangeAt(0); 15 } 16 document.body.appendChild(el); 17 el.select(); 18 el.selectionStart = 0; 19 el.selectionEnd = input.length; 20 21 var success = false; 22 try { 23 success = document.execCommand(‘copy‘); 24 } catch (err) {} 25 26 document.body.removeChild(el); 27 28 if (originalRange) { 29 selection.removeAllRanges(); 30 selection.addRange(originalRange); 31 } 32 33 return success; 34 },

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐