zoukankan      html  css  js  c++  java
  • 运行、复制、另存代码

    今天上午一个朋友找我要运行的代码,说是在网上找了好多,但是都有问题,运行不了。
    下面简单总结了一下,给用的着的朋友:

    <script language="JavaScript" type="text/JavaScript">
    //运行文本域代码
    function runCode(obj) {
    var newWin=window.open('',"_blank",'');
    newWin.document.open(
    'text/html','replace');
    newWin.opener
    =null  // 防止代码对论谈页面修改
    var Code=document.getElementById(obj).value;
    newWin.document.write(Code);
    newWin.document.close();
    }

    //复制文本域代码
    function copyCode(obj) {
    var rng = document.body.createTextRange();
    var Code=document.getElementById(obj)
    rng.moveToElementText(Code);
    rng.scrollIntoView();
    rng.select();
    rng.execCommand(
    "Copy");
    rng.collapse(
    false);
    }

    //另存代码
    function saveCode(obj) {
    var newWin=window.open('','_blank','top=10000');
    newWin.document.open(
    'text/html','replace');
    var Code=document.getElementById(obj).value;
    newWin.document.write(Code);
    newWin.document.execCommand(
    'saveas','','code.htm');
    newWin.close();
    }

    </script>

    再用onClick分别引用就可以了,例:onClick="runCode('txtCode')"

  • 相关阅读:
    派生选择器
    HTML 标签
    $.get()
    CC150
    CC150
    CC150
    CC150
    HashMap和HashTable的区别
    CC150
    quickSort
  • 原文地址:https://www.cnblogs.com/joe235/p/1136121.html
Copyright © 2011-2022 走看看