复制代码 代码如下: <BR>function copyCode(id){<BR>var testCode=document.getElementById(id).value;<BR>if(copy2Clipboard(testCode)!=false){<BR>alert("生成的代码已经复制到粘贴板,你可以使用Ctrl+V 贴到需要的地方去了哦! ");<BR>}<BR>}<BR>copy2Clipboard=function(txt){<BR>if(window.clipboardData){<BR>window.clipboardData.clearData();<BR>window.clipboardData.setData("Text",txt);<BR>}<BR>else if(navigator.userAgent.indexOf("Opera")!=-1){<BR>window.location=txt;<BR>}<BR>else if(window.netscape){<BR>try{<BR> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");<BR>}<BR>catch(e){<BR> alert("您的firefox安全限制限制您进行剪贴板操作,请打开'about:config'将 <P>signed.applets.codebase_principal_support'设置为true'之后重试,相对路径为firefox根目 <P>录/greprefs/all.js");<BR> return false;<BR>}<BR>var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance <P>(Components.interfaces.nsIClipboard);<BR>if(!clip)return;<BR>var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance <P>(Components.interfaces.nsITransferable);<BR>if(!trans)return;<BR>trans.addDataFlavor('text/unicode');<BR>var str=new Object();<BR>var len=new Object();<BR>var str=Components.classes["@mozilla.org/supports-string;1"].createInstance <P>(Components.interfaces.nsISupportsString);<BR>var copytext=txt;str.data=copytext;<BR>trans.setTransferData("text/unicode",str,copytext.length*2);<BR>var clipid=Components.interfaces.nsIClipboard;<BR>if(!clip)return false;<BR>clip.setData(trans,null,clipid.kGlobalClipboard);<BR>}<BR>}<BR> []复制内容1