zoukankan      html  css  js  c++  java
  • 博客园 中 运行js


    <p><textarea id="con" style="height: 167px;  375px; margin: 2px;">&lt;script type="text/javascript"&gt;
    alert("alert弹出?");
    &lt;/script&gt;</textarea></p>
    <p><input id="btn" onclick="btn();" type="button" value="运行代码" /></p>
    <p>&nbsp;</p>
    <p><textarea id="theCode" style=" 450px; height: 300px;" title="双击运行代码" ondblclick="runCode('theCode');">这里放入运行的Html代码。
    
    </textarea><br />
    
    <input onclick="runCode('theCode')" type="button" value="运行代码" /> 
    
    <input onclick="doCopy('theCode')" type="button" value="复制代码" /> 
    
    <input onclick="doSave('theCode','test')" type="button" value="保存代码" /></p>
    <script type="text/javascript">// <![CDATA[
    //执行代码
     
     var btn = document.getElementById("btn");
        var con = document.getElementById("con");
        if(btn && con){
            btn.onclick = function(){
                var newwin = window.open('', "_blank", '');
                newwin.document.open('text/html', 'replace');
                newwin.opener = null;
                newwin.document.write(con.value);
                newwin.document.close();
            }
        }
        function runCode(obj) {
     
            var winname = window.open('', "_blank", '');
     
            var content = document.getElementById(obj).value;
     
            winname.document.open('text/html', 'replace');
     
            winname.opener = null
     
            winname.document.writeln(content);
     
            winname.document.close();
     
        }
     
      
     
        //复制代码
     
        function doCopy(obj){
     
            var codeObj = document.getElementById(obj);
     
            clipboardData.setData('text', codeObj.innerText);
     
            alert('已经复制代码');
     
        }
     
      
     
        // 另存为文件
     
        function doSave(obj, filename){  
     
            var win = window.open('', '_blank', 'top=10000');
     
            var code = document.getElementById(obj).innerText;
     
            win.opener = null;
     
            win.document.write(code);
     
            win.document.execCommand('saveas', true, filename);
     
            win.close();
     
        }
    // ]]></script>
  • 相关阅读:
    TIF转JPG
    跨线程取出控件的值的写法(不是跨线程赋予控件值)
    oracle根据正则表达式查找对应的字段
    oracle数据库连接字符串
    access检测表没有的字段,添加之
    解决 Unable to load DLL 'OraOps9.dll': 找不到指定的模块。 (Exception from HRESULT: 0x8007007E)
    oracle关键字使用
    to_number,Extract oracle的关键字
    OracleCommand.CommandText 无效
    调用带参数的线程两种方法
  • 原文地址:https://www.cnblogs.com/laopo/p/6240687.html
Copyright © 2011-2022 走看看