2008-01-16
子窗体 焦点(转)
看一下这段代码,或许可以给你点提示,可以直接运行的:
<!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=gb2312" />
<title>父窗口</title>
<script language="javascript" type="text/javascript">
<!--
var win=null
//用于存储子窗口对象的全局变量
function output()
{
window.btn1.disabled=true;//禁用btn1,防止打开多个子窗口
var text=window.text1.value;//将要交互的值
//打开一无url的新窗口
win=window.open('','newwin','menubar=no,width=400,height=100,resizeable=no');
//定义新窗口的document对象,以便对其写入代码
var childdoc=win.document;
childdoc.writeln('<html>');
childdoc.writeln('<head>');
childdoc.writeln('<title>新开子窗口</title>');
childdoc.writeln('<script language="javascript" type="text/javascript">function check_son(str){ alert(str) }</script>')
//子窗口的测试函数
childdoc.writeln('</head>');
childdoc.writeln('<body onunload="window.opener.btn1.disabled=false">')
//关闭子窗口后父窗口的btn1恢复可用
childdoc.writeln('<input type="text" name="text2" value="'+text+'" />');
//接收父窗口传值
childdoc.writeln('<input type="button" name="Btn2" value="传回去" onclick="window.opener.text1.value=self.text2.value;window.opener.btn1.disabled=false;self.close()" />');
//将值传回到父窗口,父窗口的btn1恢复可用,关闭自身
childdoc.writeln('<input type="button" name="Btn3" value="关闭父窗口" onclick="window.opener.close()" />')
//关闭父窗口
childdoc.writeln('<input type="button" name="Btn3" value="刷新父窗口" onclick="window.opener.location.reload()" />')
//刷新父窗口
childdoc.writeln('<input type="button" name="Btn3" value="调用父窗口函数" onclick="window.opener.check_par(this.value)" />')
//调用父窗口函数
childdoc.writeln('</body>');
childdoc.writeln('</html>');
childdoc.close();
//关闭document对象
win.focus();
//子窗口取得焦点
}
function check_par(str)
{
alert(str);
}
-->
</script>
</head>
<body>
<input type="button" name="btn1" value="打开新窗口" id="btn1" onclick="output()"/>
<input name="text1" type="text" id="text1" size="10" readonly="true" value="要传递的"/>
<input type="button" name="btn2" value="关闭子窗口" id="btn2" onclick="if (win!=null) win.close()"/>
<input type="button" name="btn3" value="调用子窗口函数" id="btn3" onclick="if (win!=null) win.check_son(this.value)"/>
</body>
</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=gb2312" />
<title>父窗口</title>
<script language="javascript" type="text/javascript">
<!--
var win=null
//用于存储子窗口对象的全局变量
function output()
{
window.btn1.disabled=true;//禁用btn1,防止打开多个子窗口
var text=window.text1.value;//将要交互的值
//打开一无url的新窗口
win=window.open('','newwin','menubar=no,width=400,height=100,resizeable=no');
//定义新窗口的document对象,以便对其写入代码
var childdoc=win.document;
childdoc.writeln('<html>');
childdoc.writeln('<head>');
childdoc.writeln('<title>新开子窗口</title>');
childdoc.writeln('<script language="javascript" type="text/javascript">function check_son(str){ alert(str) }</script>')
//子窗口的测试函数
childdoc.writeln('</head>');
childdoc.writeln('<body onunload="window.opener.btn1.disabled=false">')
//关闭子窗口后父窗口的btn1恢复可用
childdoc.writeln('<input type="text" name="text2" value="'+text+'" />');
//接收父窗口传值
childdoc.writeln('<input type="button" name="Btn2" value="传回去" onclick="window.opener.text1.value=self.text2.value;window.opener.btn1.disabled=false;self.close()" />');
//将值传回到父窗口,父窗口的btn1恢复可用,关闭自身
childdoc.writeln('<input type="button" name="Btn3" value="关闭父窗口" onclick="window.opener.close()" />')
//关闭父窗口
childdoc.writeln('<input type="button" name="Btn3" value="刷新父窗口" onclick="window.opener.location.reload()" />')
//刷新父窗口
childdoc.writeln('<input type="button" name="Btn3" value="调用父窗口函数" onclick="window.opener.check_par(this.value)" />')
//调用父窗口函数
childdoc.writeln('</body>');
childdoc.writeln('</html>');
childdoc.close();
//关闭document对象
win.focus();
//子窗口取得焦点
}
function check_par(str)
{
alert(str);
}
-->
</script>
</head>
<body>
<input type="button" name="btn1" value="打开新窗口" id="btn1" onclick="output()"/>
<input name="text1" type="text" id="text1" size="10" readonly="true" value="要传递的"/>
<input type="button" name="btn2" value="关闭子窗口" id="btn2" onclick="if (win!=null) win.close()"/>
<input type="button" name="btn3" value="调用子窗口函数" id="btn3" onclick="if (win!=null) win.check_son(this.value)"/>
</body>
</html>
- 浏览: 573 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
恳请大家给点意见!!!
你想去教学,你考虑了你自己的技术有没有这个能力, 有没有兴趣,有没有这个潜力,表 ...
-- by 寄生虫 -
恳请大家给点意见!!!
我女朋友不懂技术。。。 想学。。。。。
-- by catchwang -
恳请大家给点意见!!!
回去当老师之前,泡个在做技术的妞
-- by joe001 -
恳请大家给点意见!!!
给点意见撒。。。。。
-- by catchwang






评论排行榜