标题 | JavaScript 实现完美兼容多浏览器的复制功能代码 |
内容 | 分享一段利用 JavaScript 实现复制功能的代码,兼容多浏览器,兼容IE和火狐浏览器。 <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript 复制功能代码,兼容多浏览器</title> </head> <script language="javascript"> copyValue=function(strValue){ if(isIE()){ clipboardData.setData("Text",strValue); alert("您已成功复制了此地址"); }else{ copy(strValue); alert("内容已被复制!"); } } function isIE(number){ if(typeof(number)!=number){ return!!document.all; } } function copy(text2copy){ var flashcopier = 'flashcopier'; if(!document.getElementById(flashcopier)){ var divholder = document.createElement('div'); divholder.id = flashcopier; document.body.appendChild(divholder); } document.getElementById(flashcopier).innerHTML = ''; var divinfo = '<embed src="" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键 document.getElementById(flashcopier).innerHTML = divinfo; } </script> <div> 贴图地址:<input name="txtPhotoPath" value="" id="txtPhotoPath" type="text" size="65" /> <input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('www.daimajiayuan.com');" value="复制" /> </div> </body> </html> 以上所述就是本文给大家的分享的全部内容了,希望大家能够喜欢。 |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。