如何让一个变量在不同的网页中传递呢 怎么个不同的网页?同一个网站的话可以用cookies 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 parent.htm<html><body><form id = 'frmMain' name = 'frmMain'><button onclick = 'getValue();'>getValue</button><input type = 'textbox' value = "" id = 'txtValue' name = 'txtValue' style = 'display: none'/><button id = 'btnReturn' name = 'btnReturn' onclick = 'returnValue();' style = 'display: none'></button></form><script type = 'text/javascript'><!--//var winHandler = null;function getValue(){winHandler = window.open("child.htm", "child");}function returnValue(){ alert( document.getElementById('txtValue').value ); }//--></script></body></html>child.htm<html><body><button onclick = 'btnClose_Click();'>close</button><input type = 'textbox' id = 'txtInput' value = ''/><script type = 'text/javascript'><!--//var winHandler = null;function btnClose_Click(){if (window.opener != null){ var txt = window.opener.document.frmMain.txtValue; var btn = window.opener.document.frmMain.btnReturn; if (txt != null){ txt.value = document.getElementById('txtInput').value; } btn.click();}self.close();}//--></script></body></html>我认为这个跟你说的有点类似,不妨一看. session application cookieurl get方式 form post方式 father.html<html><head><script language="javascript">function openSon(){ var abc = showModalDialog("son.html",""); document.all.txt.value = abc;}</script><head><body><form><input type = "textbox" name = "txt"/><input type = "button" name = "bt" value = "打开" onclick ="openSon()"></button></form></body></html>son.html<html><head><script language = "javascript">function returnMe(){ window.returnValue = document.all.txt.value; close();}</script><head><body><input type = "textbox" name = "txt"/><input type = "button" name ="bt" value = "确定" onclick = "returnMe()"></button></body></html>这个你试试` 跟4楼的很像. 只是窗口不同 不是很明白楼主的意思不过父界面和子界面可以传递变量可以通过下面几种方式: 子界面可以通过下面的方式返回值到父界面,由父界面使用; window.returnValue = obj;这里的obj可以是各种数据类型(js是弱语言嘛)子界面同样可以访问父界面的所有元素,包括变量,通过下面方式实现: var obj = window.dialogArguments; obj.obj2;这里的obj2可以是父界面的元素,假设父界面有个Id为"name"的元素,则子界面访问该元素,可以这样:obj.document.getElementById("name");如果obj2是父界面的变量,则直接用变量名访问:obj.变量名;声明一下,如果obj2是变量,应该是全局变量,局部变量是访问不到的 补充说明一点:如果在界面之间传递变量值,可以将变量值直接跟在路径后: var variableOne = "hello!"; window.open(url + "?amount=1&variableOne=" + variableOne);子界面可以通过下面的方式获得父界面传递过来的值: var value = GetArgsFromHrefs(location.search,"variableOne"); function GetArgsFromHrefs(sHref, sArgName) { var retval = new Array(); var args = sHref.split("?"); if(args[0] == sHref) /*参数为空*/ { return retval; /*无需做任何处理*/ } var str = args[1]; args = str.split("&"); for(var i = 0; i < args.length; i ++) { str = args[i]; var arg = str.split("="); if(arg.length <= 1) continue; if(arg[0] == sArgName) retval[retval.length] = arg[1]; } return retval;}可以加上多个变量: var variableOne = "hello,"; var variableTwo = "world!" window.open(url + "?amount=1&variableOne" + variableOne + "&variableTwo" +variableTwo);子界面同样可以通过上面的方法得到值. 求助google地图的怎么在marker旁边加一个信息框显示信息 如果图片链接里含有“年会”汉字,则ie会报错 EXT的panel实例里面可以重新设置panel的高度吗? 大家能帮忙看看如何实现这个功能吗? 求助,javascript变量传递时说传递的数据未定义 把鼠标移到一行字上,会自动弹出关于这行字的信息!怎么做?? 在输入时只想接受需要的字符,如何做到? 一个js替换脚本,能放在浏览器书签里,点一下就执行的 求点美化下拉框的代码,谢谢大家了 AngularJS中$http里面访问地址的问题 请教一下,这个是什么意思 可以控制被iframe遮住的部分可见么?
parent.htm
<html>
<body>
<form id = 'frmMain' name = 'frmMain'>
<button onclick = 'getValue();'>getValue</button>
<input type = 'textbox' value = "" id = 'txtValue' name = 'txtValue' style = 'display: none'/>
<button id = 'btnReturn' name = 'btnReturn' onclick = 'returnValue();' style = 'display: none'></button>
</form>
<script type = 'text/javascript'>
<!--//
var winHandler = null;
function getValue(){
winHandler = window.open("child.htm", "child");
}function returnValue(){
alert( document.getElementById('txtValue').value );
}
//-->
</script>
</body>
</html>child.htm<html>
<body>
<button onclick = 'btnClose_Click();'>close</button>
<input type = 'textbox' id = 'txtInput' value = ''/>
<script type = 'text/javascript'>
<!--//
var winHandler = null;
function btnClose_Click(){
if (window.opener != null){
var txt = window.opener.document.frmMain.txtValue;
var btn = window.opener.document.frmMain.btnReturn;
if (txt != null){
txt.value = document.getElementById('txtInput').value;
}
btn.click();
}
self.close();
}
//-->
</script>
</body>
</html>
我认为这个跟你说的有点类似,不妨一看.
url get方式 form post方式
father.html
<html>
<head>
<script language="javascript">
function openSon()
{
var abc = showModalDialog("son.html","");
document.all.txt.value = abc;
}
</script>
<head>
<body>
<form>
<input type = "textbox" name = "txt"/>
<input type = "button" name = "bt" value = "打开" onclick ="openSon()"></button>
</form>
</body>
</html>son.html
<html>
<head>
<script language = "javascript">
function returnMe()
{
window.returnValue = document.all.txt.value;
close();
}
</script>
<head>
<body>
<input type = "textbox" name = "txt"/>
<input type = "button" name ="bt" value = "确定" onclick = "returnMe()"></button>
</body>
</html>
这个你试试` 跟4楼的很像. 只是窗口不同
不过父界面和子界面可以传递变量可以通过下面几种方式:
子界面可以通过下面的方式返回值到父界面,由父界面使用; window.returnValue = obj;这里的obj可以是各种数据类型(js是弱语言嘛)子界面同样可以访问父界面的所有元素,包括变量,通过下面方式实现: var obj = window.dialogArguments;
obj.obj2;这里的obj2可以是父界面的元素,假设父界面有个Id为"name"的元素,
则子界面访问该元素,可以这样:
obj.document.getElementById("name");
如果obj2是父界面的变量,则直接用变量名访问:obj.变量名;
声明一下,如果obj2是变量,应该是全局变量,局部变量是访问不到的
如果在界面之间传递变量值,可以将变量值直接跟在路径后: var variableOne = "hello!";
window.open(url + "?amount=1&variableOne=" + variableOne);子界面可以通过下面的方式获得父界面传递过来的值: var value = GetArgsFromHrefs(location.search,"variableOne");
function GetArgsFromHrefs(sHref, sArgName) {
var retval = new Array();
var args = sHref.split("?");
if(args[0] == sHref) /*参数为空*/
{
return retval; /*无需做任何处理*/
}
var str = args[1];
args = str.split("&");
for(var i = 0; i < args.length; i ++)
{
str = args[i];
var arg = str.split("=");
if(arg.length <= 1) continue;
if(arg[0] == sArgName) retval[retval.length] = arg[1];
}
return retval;
}可以加上多个变量: var variableOne = "hello,";
var variableTwo = "world!"
window.open(url + "?amount=1&variableOne" + variableOne + "&variableTwo" +variableTwo);子界面同样可以通过上面的方法得到值.