<div id="butt">
<input type="button" value="提交代码" onclick="show()">
</div><div id="CodeArea">
<br/>
<h2>编辑您的代码:</h2>
<textarea id="TestCode" wrap="logical">
<html><body><img src="\website1\image\eg_landscape.jpg"></img><p>一些老的浏览器不支持 iframe。</p>
<p>如果得不到支持,iframe 是不可见的。</p>
</body>
</html>
</textarea>
</div></form><div id="result">
<h2>查看结果:</h2>
<iframe frameborder="0" name="i" src="temp.htm"></iframe>
</div>
我该怎么编写javascript代码让textarea的内容在temp.htm里面显示

解决方案 »

  1.   


      function show(){
     
      frames["i"].document.write( document.getElementById('TestCode').value)
      }
      

  2.   

    主html<!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=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    </head><body>
    <div id="butt">
    <input type="button" value="提交代码">
    </div><div id="CodeArea">
    <br/>
    <h2>编辑您的代码:</h2>
    <textarea id="TestCode" wrap="logical">
    <p>一些老的浏览器不支持 iframe。</p>
    <p>如果得不到支持,iframe 是不可见的。</p>
    </textarea></div></form><div id="result">
    <h2>查看结果:</h2>
    <iframe frameborder="0" id="broele" name="i" src="temp.html"></iframe>
    </div>
    <script type="text/javascript">
    jQuery(function($){
    $('#butt').find('input').click(function(){
    $('#broele').contents().find('body').html($('#TestCode').html());
    });});
    </script>
    </body>
    </html>temp.html就是一个空的html模板<!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=utf-8" />
    <title>无标题文档</title>
    </head><body>
    </body>
    </html>
      

  3.   

    我如果想用js实现这个过程,那么我该怎么编写我的js文档呢
      

  4.   

    读不出来         求查下错function show(){
    var t=document.getElementById("TestCode").value;  
      //提取textarea的内容
    Var fso=new ActiveXObject(Scripting.FileSystemObject);
    Var f=fso.CreateTextFile(“d:\website11\temp.htm”,2,true);
    //创建文件temp.htm
    f.write(t);
    f.close();
    //将提取到的textarea的内容写入temp.htm
    doucument.getElementById("i")[0].scr="temp.htm";
    //将ifame的src属性值改为temp.htm
    }
      

  5.   

    你这是写文件.每次textarea内容变化时都去写一个temp.html.用javascript实现没有必要这么麻烦
      

  6.   

    frames[i].document.innerHTML = document.getElementById('TestCode').value;
      

  7.   

    这个不是iframe的嵌套吗?不能再父页面中使用document.getElementById(IframeID).contentWindow  获取到子页面中的window 对象去操作吗?