国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

JavaScript 實(shí)現(xiàn)完美兼容多瀏覽器的復(fù)制功能代碼

2024-05-06 16:18:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這兩天在做Web前端時(shí),遇到需求通過(guò)js實(shí)現(xiàn)文本復(fù)制的功能。經(jīng)過(guò)一番測(cè)試,終于實(shí)現(xiàn)了出來(lái),有需要的小伙伴可以參考下。

分享一段利用 JavaScript 實(shí)現(xiàn)復(fù)制功能的代碼,兼容多瀏覽器,兼容IE和火狐瀏覽器。

 

 
  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>JavaScript 復(fù)制功能代碼,兼容多瀏覽器</title>  
  5. </head>  
  6. <script language="javascript">  
  7. copyValue=function(strValue){  
  8. if(isIE()){  
  9. clipboardData.setData("Text",strValue);  
  10. alert("您已成功復(fù)制了此地址");  
  11. }else{  
  12. copy(strValue);  
  13. alert("內(nèi)容已被復(fù)制!");  
  14. }  
  15. }  
  16. function isIE(number){  
  17. if(typeof(number)!=number){  
  18. return!!document.all;  
  19. }  
  20. }  
  21. function copy(text2copy){  
  22. var flashcopier = 'flashcopier';  
  23. if(!document.getElementById(flashcopier)){  
  24. var divholder = document.createElement('div');  
  25. divholder.id = flashcopier;  
  26. document.body.appendChild(divholder);  
  27. }  
  28. document.getElementById(flashcopier).innerHTML = '';  
  29. var divinfo = '<embed src="http://files.vevb.com/demoimg/200910/_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//這里是關(guān)鍵  
  30. document.getElementById(flashcopier).innerHTML = divinfo;  
  31. }  
  32. </script>  
  33. <div class="phoinfo">  
  34. 貼圖地址:<input name="txtPhotoPath" value="www.daimajiayuan.com" id="txtPhotoPath" type="text" size="65" />  
  35. <input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('www.daimajiayuan.com');" value="復(fù)制" />  
  36. </div>  
  37. </body>  
  38. </html> 

以上所述就是本文給大家的分享的全部?jī)?nèi)容了,希望大家能夠喜歡。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 沙湾县| 金沙县| 马尔康县| 达拉特旗| 蕉岭县| 台湾省| 高要市| 巨野县| 乐陵市| 都安| 濮阳县| 怀仁县| 遂溪县| 丁青县| 玉龙| 北辰区| 诏安县| 山东省| 五河县| 新民市| 桐庐县| 报价| 资兴市| 叶城县| 北碚区| 定州市| 镇平县| 石渠县| 阜平县| 弋阳县| 堆龙德庆县| 鹤壁市| 增城市| 防城港市| 房产| 广元市| 黔东| 涡阳县| 壤塘县| 读书| 班戈县|