文本编辑器: 运行代码,复制到剪贴板,另存为

<script type="text/javascript"> $ = function (id){ return document.getElementById(id); } function copycode(obj){ window.clipboardData.setData("Text",obj.value); alert("代码复制成功!") } function oCopy(objname){ var obj = $(objname); obj.select(); js=obj.createTextRange(); js.execCommand("Copy"); alert("源码爱好者提示:代码已经被成功复制!"); } var lang = new Array(); var userAgent = navigator.userAgent.toLowerCase(); var is_opera = userAgent.indexOf('opera') != -1 && opera.version(); var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3); var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3); Array.prototype.push = function(value) { this[this.length] = value; return this.length; } function $(objname){return document.getElementById(objname);} function runCode(objname) { var winname = window.open('', "_blank", ''); var obj = $(objname); winname.document.open('text/html', 'replace'); winname.opener = null // 防止代码对论谈页面修改 winname.document.write(obj.value); winname.document.close(); } function saveCode(objname){ var winname = window.open('', '_blank', 'top=10000'); winname.document.open('text/html', 'replace'); var obj = $(objname); winname.document.write(obj.value); winname.document.execCommand('saveas','','code.htm'); winname.close(); } </script> <textarea style='padding: 3px; font-family: "Courier New",Courier,monospace;' class="pt" cols="96" rows="12" id="content" name="content"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> JS复制到剪切板</title> </head> <script> function showDivLinkCopy() { var msg=document.getElementById("text").value; window.clipboardData.setData("Text",msg); } </script> <body> <input name="" type="text" id="text" value="点击右边的复制" style=" border:1px solid #ccc; padding:4px; font-size:14px; color:#444; width:200px; line-height:20px;" /> <a href="javascript:void(0);" οnclick="showDivLinkCopy()" style="padding-left:15px; line-height:30px; font-size:16px;"> 复制</a> </body> </html> </textarea> <p class="mtn"> <input οnclick="runCode('content')" name="Submit" value="运行代码" type="button"> <input οnclick="$('content').select();" name="Submit3" value="全选代码" type="button"> <input οnclick="oCopy('content')" name="Submit4" value="复制代码" type="button"> <button οnclick="copycode($('content'))" > <em> 复制代码 js : copycode</em> </button> <input οnclick="saveCode('content')" name="Submit2" value="保存代码" type="button"> </p>

转载于:https://www.cnblogs.com/miciing/archive/2012/12/14/js.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值