运行代码

View Code
window.onload=function()
{
    var txt=document.getElementById('txt');
    var oBtn=document.getElementById('btn');
    
    oBtn.onclick=function()
    {
        var oWindow=window.open('about:blank','_blank');
        oWindow.document.write(txt.value);
        txt.value='';
    };
};
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <script>
 7 window.onload=function()
 8 {
 9     var txt=document.getElementById('txt');
10     var oBtn=document.getElementById('btn');
11     
12     oBtn.onclick=function()
13     {
14         var oWindow=window.open('about:blank','_blank');
15         oWindow.document.write(txt.value);
16         txt.value='';
17     };
18 };
19 </script>
20 </head>
21 
22 <body>
23 <textarea id="txt" rows="10" cols="40"></textarea><br />
24 <input type="button" value="运行代码" id="btn" />
25 </body>
26 </html>

 

posted @ 2013-04-12 17:47  yexingwen  阅读(507)  评论(0编辑  收藏  举报