BOM之Window案例

效果:主窗口有用户编号和姓名文本框,点击选择,打开新窗口,选择对应人名,人名和编号会出现在第一个窗口中,新打开的窗口随之关闭。

提示:谷歌浏览器看不到效果,用IE。






主窗口

<body>
	<div>
		用户编号:<input type="text" id="ID" /><br/>
		用户姓名:<input type="text" id="name" /><br/>
		<input type="button" value="选择" οnclick="run1()"/>
		
	</div>
</body>
<script type="text/javascript">
	//alert(window.document.getElementById("ID").value);
	function run1()
	{
		window.open("eg1ps.html", "", "width=300,height=300");
	}
</script>

打开的窗口

<body>
	<table border="1" width="100%">
		<tr align="center">
			<th>操作</th>
			<th>编号</th>
			<th>姓名</th>
		</tr>
		<tr align="center">
			<td>
				<input type="button" value="选择" οnclick="run1()"/>
			</td>
			<td id="id1">1</td>
			<td id="name1">Ramon</td>
			
		</tr>
		<tr align="center">
			<td>
				<input type="button" value="选择" id="2" οnclick="run2()"/>
			</td>
			<td id="id2">2</td>
			<td id="name2">Ali</td>
		</tr>
		<tr align="center">
			<td>
				<input type="button" value="选择" id=3 οnclick="run3()"/>
			</td>
			<td id="id3">3</td>
			<td id="name3">Aryan</td>
		</tr>
	</table>
</body>
<script type="text/javascript">
	
	var windows=window.opener;
	function run1(){
		var i=window.document.getElementById("id1").innerHTML;
		var n=window.document.getElementById("name1").innerHTML;
	    	windows.document.getElementById("ID").value=i;
		windows.document.getElementById("name").value=n;
		window.close();
	}
	function run2(){
		var i=window.document.getElementById("id2").innerHTML;
		var n=window.document.getElementById("name2").innerHTML;
	        windows.document.getElementById("ID").value=i;
		windows.document.getElementById("name").value=n;
		window.close();
	}
	function run3(){
		var i=window.document.getElementById("id3").innerHTML;
		var n=window.document.getElementById("name3").innerHTML;
	    	windows.document.getElementById("ID").value=i;
		windows.document.getElementById("name").value=n;
		window.close();
	}
</script>



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值