posts - 104,  comments - 34,  trackbacks - 0

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
          <title>textarea</title>
          <script type="text/javascript">
           function runCode(obj) {
            var winname = window.open('', "_blank", '');
            winname.document.open('text/html', 'replace');
            //winname.opener = null // 防止代碼對(duì)原頁(yè)面修改
            winname.document.write(obj.value);
            winname.document.close();
           }
           function saveCode(obj) {
            var winname = window.open('', '_blank', 'top=10000');
            winname.document.open('text/html', 'replace');
            winname.document.writeln(obj.value);
            winname.document.execCommand('saveas','','code.htm');
            winname.close();
           }
           function copyCode(obj) {
            var rng = document.body.createTextRange();
            rng.moveToElementText(obj);
            rng.scrollIntoView();
            rng.select();
            rng.execCommand("Copy");
            rng.collapse(false);
           }
          </script>
          </head>

          <body>
          <textarea id="code" rows="10" cols="95">
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
          <title>測(cè)試文檔</title>
          </head>
          <body>測(cè)試文檔
          </body>
          </html>
          </textarea><br>
          <input type="button" value="運(yùn)行代碼" onclick="runCode(code)">&nbsp;
          <input type="button" value="復(fù)制代碼" onclick="copyCode(code)">&nbsp;
          <input type="button" value="另存代碼" onclick="saveCode(code)">&nbsp;
          提示:您可以先修改部分代碼再運(yùn)行<br />
          </body>
          </html>

          posted on 2007-12-11 14:01 末日風(fēng)情 閱讀(620) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): HTML/XMLjavascript

          FeedBack:
          # re: textarea實(shí)現(xiàn)運(yùn)行代碼功能
          2008-08-26 01:36 | 1132
          謝了。很有用。  回復(fù)  更多評(píng)論
            
          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(4)

          隨筆分類(lèi)

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 白城市| 九江市| 赤城县| 上高县| 炉霍县| 隆林| 古交市| 新田县| 台东县| 宣恩县| 颍上县| 芦山县| 彩票| 巴南区| 通渭县| 承德县| 丰原市| 介休市| 松原市| 涞源县| 高阳县| 阿合奇县| 长武县| 大厂| 桃园市| 肇庆市| 上杭县| 辽阳县| 唐山市| 北川| 祁东县| 望都县| 黄梅县| 沁水县| 北海市| 元氏县| 顺昌县| 眉山市| 弥勒县| 宜兰市| 邯郸县|