<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里面显示
function show(){
frames["i"].document.write( document.getElementById('TestCode').value)
}
<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>
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
}