要使用的框架的页面代码:
<body> <form id="form1" runat="server"> <div> <div style="float: left; margin-top: 150px;"> <iframe id="menu" src="index.aspx" scrolling="no" frameborder="0" width="200px"></iframe> </div> <div style="float: right; margin-right: 500px;"> 这里是页面内容,这个页面,适用于测试iframe的用法 </div> </div> </form> </body>
<script type="text/javascript"> window.onload = function () { var frame = window.frames['menu']; var a = document.getElementById('menu').contentWindow.document.getElementById('slt'); alert(a.value); a.value = 'zj'; }; /*menu是iframe标签的id,slt是框架里要选取元素的ID*/ </script>
框架内的代码:
<body> <form id="form1" runat="server"> <div> <label> 城市选择:</label> <select id="slt"> <option value="cz">常州市</option> <option value="nt">南通市</option> <option value="zj">镇江市</option> <option value="yz">扬州市</option> </select> </div> </form> </body>