日期:2014-05-16  浏览次数:20398 次

javascript,js,简单的iframe高度自适应

?

共两个文件

?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery</title>
<style type="text/css">
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<!-- <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> -->
<script type="text/javascript">
</script>
</head> 
 
<body> 
	<div id="p_iframe" style="display:block">
		<iframe id="my_iframe" scrolling="auto" src="http://localhost/test/test2.html"></iframe>
	</div>
 </body>
</html>

?

<!DOCTYPE html>
<html>
<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.4.2/jquery.min.js"></script>
<title>iframe src</title>
<script type="text/javascript">
$(document).ready(function (){
	alert('ee');
	parent.document.getElementById("my_iframe").height=parseInt(document.documentElement.scrollHeight)+0;
	alert('ddd');
});
</script>
</head>
<body>
	<br /><br />
	用户名:<input type="text" /><br /><br /><br />
	密&nbsp;&nbsp;码:<input type="password" /><br /><br /><br />
	<input type="button" value="提交"/><br /><br /><br />
	<input type="reset" value="重置"/>
</body>
</html>
?

?