想关代码:function runCode()  //定义一个运行代码的函数,
{
  var code=event.srcElement.parentElement.children[0].value;
  var newwin=window.open('','','height=400, width=650, top=0,left=0,toolbar=1, menubar=1, scrollbars=1, resizable=1, location=1, status=1');
  newwin.opener = null // 防止代码对论谈页面修改
  newwin.document.write(code);
  newwin.document.close();
  newwin.document.charset="UTF-8";
}<input type="button" value="运行代码" onclick="runCode();">

解决方案 »

  1.   

    保存代码 onclick=saveFile()<SCRIPT language=JavaScript>
    function runEx(){
    var winEx2 = window.open("", "winEx2",""); winEx2.document.open("text/html", "replace"); 
    winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value)); 
    winEx2.document.close(); 
    }
    function saveFile()
    {
      var win=window.open('','','top=10000,left=10000');
      win.document.write(document.all.asdf.innerText)
      win.document.execCommand('SaveAs','','copy.htm')
      win.close();
    }
    </SCRIPT>
    复制代码 onclick="JM_cc('textfield')"<SCRIPT language=JavaScript>
    <!--function MM_goToURL() { //v3.0
      var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
      for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }
    function JM_cc(ob){
    var obj=MM_findObj(ob); if (obj) { 
    obj.select();js=obj.createTextRange();js.execCommand("Copy");}
    }function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }
    //--></SCRIPT>