笔记-关于从textarea传递到iframe(for firfox)

ie的还未整合
参考文献:
http://developer.mozilla.org/en/DOM
http://www.w3school.com.cn/htmldom/index.asp
<html>
	<head>
		<script language="javascript">
			function test(){
				var iframe = document.getElementById("test");
				var d = iframe.contentDocument;
				var t = d.body.innerHTML;
				d.body.innerHTML = ta.value;
			}
			function sh(){
				ta.value = iframe.contentDocument.body.innerHTML;
			}  
		</script>
	</head>
	<body>
		<iframe id="test" width="50%" height="100px"></iframe><br/>
		<textarea id="ta" style="width:50%; height:100px;"></textarea>
		<script language="javascript">
			var iframe = document.getElementById("test");
			var ta = document.getElementById("ta");
			iframe.contentEditable="true";
			iframe.contentDocument.designMode="On";
			iframe.contentDocument.open();
			iframe.contentDocument.write("<html><body></body></html>");
			iframe.contentDocument.open();
		</script>
		<br/>
		<input type="submit" onClick="test()" value="click" />
		<input type="submit" onClick="sh()" value="show" />
	</body>
</html>  


作为对比,看看另一个在ie中可以运行的例子
code/iframe.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<title>iframe</title>
</head> 
<body>
<div id="div">This is a div</div><br />
<input id ="input" value="This is a input" /><br /><br />
<input id ="button" type="button" value="This is a button" />

</body> 
</html> 

<iframe src="code/iframe.htm" id="iframe" ></iframe>
<script type="text/javascript" src="prototye.js"></script>
<script type="text/javascript">
    function getINPUT()
    {
        var iframe = $('iframe').contentWindow;
        alert(iframe.input.value);

    }
      function getDIV()
    {
        var iframe = $('iframe').contentWindow;
        alert(iframe.div.innerHTML);

    }
    function getBUTTON()
    {
        var iframe = $('iframe').contentWindow;
        alert(iframe.button.value);

    }
</script>
<br />
<input type="button" value="GetDiv" onclick="getDIV()" id ="GetDiv"/>
<input type="button" value="GetInput" onclick="getINPUT()" id ="GetInput"/>
<input type="button" value="GetButton" onclick="getBUTTON()" id ="GetButton"/>

你可能感兴趣的:(html,XHTML,IE,asp,idea)