代码运行框

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
    <html>  
      <head>  
        <title>coder</title>  
          
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
        <meta http-equiv="description" content="this is my page">  
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">  
        <style>  
        #container  #code{  
                width:400px;  
                height:200px;  
                resize:none;  
                background:none;  
                border:1px solid gray;  
            }  
        #container button ,#container .btn{  
            border:1px solid gray;  
            cursor:pointer;  
            padding:0px;  
            width:75px;  
            height:23px;  
        }  
        #container button:hover,#container .btn:hover{  
              
        }  
        </style>  
        <script type="text/javascript">  
            function  Coder (id) {  
                this.id = id;  
                this.$ = function(id) {  
                    return document.getElementById(id);  
                }  
                this.runcode  = function() {  
                    var codeWin = window.open("about:blank","_blank")  
                    codeWin.document.writeln(this.obj.value);  
                    return codeWin;  
                }  
                this.savecode  = function() {  
                    var codeWin = this.runcode();  
                    var title = codeWin.document.title || "code" ;            
                    codeWin.document.execCommand("SaveAs",false,title+".html");  
                    codeWin.close();  
                }  
                this.printcode  =function() {  
                    var codeWin = this.runcode();  
                    codeWin.document.execCommand("Print",false,"");  
                    codeWin.close();  
                }  
                this.init=function() {  
                    this.obj = this.$(this.id);  
                    var context = this;  
                    this.$("run").onclick = function() {  
                        context.runcode();  
                    };  
                    this.$("save").οnclick=function(){  
                        context.savecode();  
                    }  
                    this.$("print").οnclick=function(){  
                        context.printcode();  
                    }  
                }  
            }  
        var coder = new Coder("code");  
        window.onload = function() {coder.init();};  
      
        </script>  
       </head>  
       <body>  
            <h3>请输入代码:</h3>  
            <div id="container">  
                <p><textarea id="code"><!DOCTYPE html>  
    <html>  
        <head>  
            <title>coder</title>  
        </head>  
        <body>  
              
        </body>  
    </html></textarea></p>  
                <button type="button" id="run">运行</button>  
                <button type="button" id="save">保存</button>  
                <button type="button" id="print">打印</button>  
            </div>  
        </body>  
    </html>  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值