頁面傳值的方案

liuhui810 2009-07-06 03:41:16
在主頁面點擊按鈕,彈出一個模式窗口,輸入值后,點擊完成按鈕,父頁面的某個textbox可以根據模式窗口的值改變而改變。
怎麽實現?
謝謝。
...全文
35 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuhui810 2009-07-07
  • 打赏
  • 举报
回复
謝謝lihui_shine ,真厲害。
浪尖赏花 2009-07-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 liuhui810 的回复:]
首先謝謝各位。一個值返回沒有問題了。

那如果是要從子窗口獲取多個值,怎麽辦?
用window.returnValue獲取字符串數組嗎?
[/Quote]
一样的道理,直接向window.returnValue赋值就行了
a.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
<script>
function setValue(){
var ret = window.showModalDialog("b.htm",'','');
document.getElementById("txt1").value=ret[0];
}
</script>
</head>

<body>
<input type=text value="" id=txt1 readonly>
<input type=button onclick=setValue() value="set value">
</body>

</html>

b.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>b</title>
<script>
function on_submit(){
window.returnValue=[document.getElementById("txt2").value,document.getElementById("txt3").value,document.getElementById("txt4").value];
window.close();
}
</script>
</head>

<body>
<input type="text" value="" id="txt2">
<input type="text" value="" id="txt3">
<input type="text" value="" id="txt4">
<input type=button value=submit onclick="on_submit()">
</body>

</html>
liuhui810 2009-07-07
  • 打赏
  • 举报
回复
首先謝謝各位。一個值返回沒有問題了。

那如果是要從子窗口獲取多個值,怎麽辦?
用window.returnValue獲取字符串數組嗎?
thinsoft 2009-07-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gengzhw 的回复:]
引用 1 楼 lihui_shine 的回复:
a.htm
b.htm


UP
[/Quote]
up
linuxlsx 2009-07-06
  • 打赏
  • 举报
回复
1L 正解 lz在子页面也可以获得父窗口传过来的值 showModalDialog()的第二个参数就是父窗口传向子窗口的值
在字窗口使用 dialogArgument接收这个值
gengzhw 2009-07-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lihui_shine 的回复:]
a.htm
b.htm
[/Quote]
UP
monexus 2009-07-06
  • 打赏
  • 举报
回复
模式或非模式都可用
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function openPage(page){
var arg = {
window: window,
input: document.getElementById('input')
};
//window.showModelessDialog(page, arg, 'status:no;edge:sunken;dialogWidth:600px;dialogHeight:350px');
window.showModalDialog(page, arg, 'status:no;edge:sunken;dialogWidth:600px;dialogHeight:350px');
}
</script>
</head>
<body>
<a hre="#" onclick="openPage('input.html');" style="cursor:hand">open</a>
<textarea id="input"></textarea>
</body>
</html>


input.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var arg = window.dialogArguments;
window.onload =function(){
var done = document.getElementById('done'),
input = document.getElementById('input');
done.onclick = function(){
arg.input.value = input.value;
}
}
</script>
</head>
<body>
<textarea id="input"></textarea>
<input type="button" id="done" value="done" />
</body>
</html>
浪尖赏花 2009-07-06
  • 打赏
  • 举报
回复
a.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
<script>
function setValue(){
var ret = window.showModalDialog("b.htm",'','');
document.getElementById("txt1").value=ret;
}
</script>
</head>

<body>
<input type=text value="" id=txt1 readonly>
<input type=button onclick=setValue() value="set value">
</body>

</html>

b.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>b</title>
<script>
function on_submit(){
window.returnValue=document.getElementById("txt2").value;
window.close();
}
</script>
</head>

<body>
<input type="text" value="" id="txt2">
<input type=button value=submit onclick="on_submit()">
</body>

</html>

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧