这个问题困扰了好久了,论坛上一直没有找到。
有三个页面,1.html中嵌入了iframe 2.html,在2.html中使用了一个showModalDialog的弹出窗口,我想实现把2.html弹出窗口的值传回到1.html的文本框中
1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body> <input type="text" id="txtfile">
<iframe src="2.html" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" width="700" height="460"></iframe>
</body>
</html>2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<script>
function winopen()
{
window.showModalDialog("3.html", window, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
}
</script>
<input type="button" value="弹出窗口" onclick="winopen();">
</body>
</html>3.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<script>
function test()
{
parent.document.getElementById("txtfile").value = "ok";
}
</script>
<input type="button" value="测试" onclick="test();">
</body>
</html>
有三个页面,1.html中嵌入了iframe 2.html,在2.html中使用了一个showModalDialog的弹出窗口,我想实现把2.html弹出窗口的值传回到1.html的文本框中
1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body> <input type="text" id="txtfile">
<iframe src="2.html" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" width="700" height="460"></iframe>
</body>
</html>2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<script>
function winopen()
{
window.showModalDialog("3.html", window, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
}
</script>
<input type="button" value="弹出窗口" onclick="winopen();">
</body>
</html>3.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<script>
function test()
{
parent.document.getElementById("txtfile").value = "ok";
}
</script>
<input type="button" value="测试" onclick="test();">
</body>
</html>
解决方案 »
- JQuery
- BS结构或BS结构的PHP JavaScript 能获取客户端硬件信息吗?
- 【Ext】一个按钮鼠标放上去时变换图片应该怎么做,请高手指点
- 求一JS特效 关于图片的
- Widget小程序主要使用什么语言实现?
- 求一个JAVASCRIPT验证时间的函数,谢谢了~~
- js 怎样访问其他页面的表单啊
- 关闭窗口时获取的clentX杂个不是主窗口的值,而是跟formeset有关?
- 在JS中有没有想C中的DELAY()或是SLEEP()的函数?
- 关于 Extjs store 加载 json 对象的问题.
- 个人写了段js代码,运行时 ie出现导致运行速度减慢
- new Ext.window中 如何调用第三方打印控件?
要传回到1.html的文本框中,只需要在2.html中用 window.parent.document.getElementById('txtfile').value=你那个值; 这样就行了.
function test()
{
parent.document.getElementById("txtfile").value = "ok";
}我就是这样写的,不行,提示找不到txtfile
不能找到1.html的txtfile,试试window.parent.parent.document.getElementById("txtfile").value ="ok"
function callback(a){
parent.document.getElementById("txtfile").value =a;
}
function winopen()
{
window.showModalDialog("3.html", callback, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
}3.html的
function test(){
var myObj = window.dialogArguments;
var a='';//你需要传的值
myObj(a);
}
现在一看,是你对showModalDialog的使用有问题.有两种修改方法:
第 1种,最接近你原来的方式,但不一定行:2.html里
window.showModalDialog("3.htm",window,"dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");3.html里
function test()
{
window.dialogArguments.parent.document.getElementById("txtfile").value = "ok";
}
第 2种:2.html里
var 在2里接收到的返回值=window.showModalDialog("3.htm",, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
window.parent.document.getElementById('txtfile').value=在2里接收到的返回值;3.html里
在返回之前,用 window.returnValue="ok";