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>
  • 相关阅读:
    日记功能发布
    功能小改进
    CuteEditor 6.0一个很奇怪的Bug
    关于博客园.NET俱乐部的公告
    新功能发布
    建立了一个博客园创业者QQ群
    思想决定生活 《卡耐基成功之道全书》读书笔记
    建立了一个英语学习小组
    实际上我没有选择的余地
    公告
  • 原文地址:https://www.cnblogs.com/laopo/p/6240687.html
Copyright © 2011-2022 走看看