頁面傳值的方案 在主頁面點擊按鈕,彈出一個模式窗口,輸入值后,點擊完成按鈕,父頁面的某個textbox可以根據模式窗口的值改變而改變。怎麽實現?謝謝。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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> 模式或非模式都可用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> 1L 正解 lz在子页面也可以获得父窗口传过来的值 showModalDialog()的第二个参数就是父窗口传向子窗口的值在字窗口使用 dialogArgument接收这个值 首先謝謝各位。一個值返回沒有問題了。那如果是要從子窗口獲取多個值,怎麽辦?用window.returnValue獲取字符串數組嗎? 一样的道理,直接向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> 謝謝lihui_shine ,真厲害。 关于取消冒泡的问题~请教大家了 急求,jquery ui 的问题 js代码的意思 关于正则表达式 RegExp Pattern $1 用一个一分钟的倒计时,倒计时完了后能显示出一个按钮javascript做 左侧导航栏中的一个元素能不能拖动到右边的iframe中 请问:各位朋友们谁有判断身份证号和判断电子信箱是否正确的JavaScript函数?先谢谢了! 急!为什么浏览器不能运行*.class文件了,在线等... 传递参数问题。 如何让层内的文字不自动换行 急,出事了,javascript的close关闭问题? form提交后 里面的什么标签的内容都被传到服务器???
<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>
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>
在字窗口使用 dialogArgument接收这个值
用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>