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

前端之家收集整理的这篇文章主要介绍了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 },

猜你在找的Cocos2d-x相关文章