2html页面,js传值问题 有1.html和2.html 这两个页面,目标:打开1.html点击按钮,弹出2.html页面,input框里输入信息,点击确定,关闭窗口,信息传递给1.html的input框里,请问如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你在1页面加一个超链接跳转到2页面,然后再2页面使用<%%>吧数据保存到session中,然后关闭2页面一页面可以得到值。最土的方法这是。 下面是两个页面的代码,纯html+js的,已在IE8上测试验证过。楼主要做的这个是很基本的功能,建议用jQuery的easyUI或extJs等成熟组件,既美观又方便。1.html的代码:<html> <head> <title>1</title> <Script language="javascript"> function GetRequest() { var url = location.search; var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); } } return theRequest; } function PageLoad(){ var Request = new Object(); Request = GetRequest(); if(null == Request['inputTxt'] || "undefined"== Request['inputTxt']) document.getElementById("txtShow").value = ""; else document.getElementById("txtShow").value = Request['inputTxt']; } function open2(){ window.open("2.html"); }</Script> </head> <body onload="PageLoad();"> <input type="text" id="txtShow" /> <input type="button" id="btnC" value="Change" onclick="window.open('2.html');" /> </body></html>2.html的代码:<html> <head> <title>2</title> <script type="text/javascript"> function GoOne(){ var inputTxt = document.getElementById("txt").value; window.opener.document.location = "1.html?inputTxt="+inputTxt; window.close(); } </script> </head> <body> <input type="text" id="txt" /> <input type="button" id="btnS" value="OK" onclick="GoOne();"/> </body></html> 1.html的代码:<html> <head> <title>1</title> <Script language="javascript"> function openWindow(){ window.open("listAttas.jsp", "aaaa", "height=550,width=780,status=yes,toolbar=no,menubar=no,location=no"); } function getvalue(data){document.getElementById("txtShow").value=data;} </Script> </head> <body > <input type="text" id="txtShow" /> <input type="button" id="btnC" value="Change" onclick="openWindow();" /> </body></html> 2.html的代码:<html> <head> <title>2</title> <script type="text/javascript">function GoOne(){window.opener.getvalue(document.getElementById("txt").value);window.close();} </script> </head> <body> <input type="text" id="txt" /> <input type="button" id="btnS" value="OK" onclick="GoOne();"/> </body></html> 上面主要是通过window.opener.getvalue(document.getElementById("txt").value);这段代码传值的,然后父窗体getvalue方法接收这个参数。其中listAttas.jsp就是你2.html,试试吧。第一次回复别人文本格式都给错了-_-||| 多个项目之间传递参数问题 JSP JDBC-ODBC连接查询中提示数据库操作语句错误 放dll的问题! 刚才哪个问题还是没有解决, 请大吓在帮帮忙!!1 怎么实现一次上传多个附件? 能否选中普通表格的一行? 关于存储过程及其调用(先到先得分) 求JSP一代码 为什么我找不到bean? java web 如何实现ip登录 关于ssh搭配框架问题 遇到一个异常 有人能给点提示吗?
1.html的代码:<html>
<head>
<title>1</title>
<Script language="javascript">
function GetRequest() {
var url = location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
function PageLoad(){
var Request = new Object();
Request = GetRequest();
if(null == Request['inputTxt'] || "undefined"== Request['inputTxt'])
document.getElementById("txtShow").value = "";
else
document.getElementById("txtShow").value = Request['inputTxt'];
}
function open2(){
window.open("2.html");
}
</Script>
</head>
<body onload="PageLoad();">
<input type="text" id="txtShow" />
<input type="button" id="btnC" value="Change" onclick="window.open('2.html');" />
</body>
</html>2.html的代码:<html>
<head>
<title>2</title>
<script type="text/javascript">
function GoOne(){
var inputTxt = document.getElementById("txt").value;
window.opener.document.location = "1.html?inputTxt="+inputTxt;
window.close();
}
</script>
</head> <body>
<input type="text" id="txt" />
<input type="button" id="btnS" value="OK" onclick="GoOne();"/>
</body>
</html>
<head>
<title>1</title>
<Script language="javascript">
function openWindow(){
window.open("listAttas.jsp", "aaaa", "height=550,width=780,status=yes,toolbar=no,menubar=no,location=no");
}
function getvalue(data){
document.getElementById("txtShow").value=data;
}
</Script>
</head>
<body >
<input type="text" id="txtShow" />
<input type="button" id="btnC" value="Change" onclick="openWindow();" />
</body>
</html>
2.html的代码:<html>
<head>
<title>2</title>
<script type="text/javascript">
function GoOne(){
window.opener.getvalue(document.getElementById("txt").value);
window.close();
}
</script>
</head> <body>
<input type="text" id="txt" />
<input type="button" id="btnS" value="OK" onclick="GoOne();"/>
</body>
</html>