点击按钮后Second.html会重新弹出一个页面,怎么才能实现在当前页打开?类似于A标签的target="_parent"?
因为这两个都是静态页面,second.html要接受First.html的值,我想用window.open()的方法,请问该怎么解决?<html><head><title...
因为这两个都是静态页面,second.html要接受First.html的值,我想用window.open()的方法,请问该怎么解决?
<html>
<head>
<title>测试</title>
<script type="text/javascript">
function checkAll()
{
var result=0;
var aa = document.getElementsByName("checkbox");
for (var i=0; i<aa.length; i++){
result+=parseFloat((aa[i]).value);
}
document.form1.txt.value+=result;
window.open("Second.html");
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="checkbox" name="checkbox" value="1" id="checkbox" />
<input type="checkbox" name="checkbox" value="2" id="checkbox" />
<input type="button" value="btn" name="btn" onClick="checkAll()">
</form>
</body>
</head>
</html> 展开
<html>
<head>
<title>测试</title>
<script type="text/javascript">
function checkAll()
{
var result=0;
var aa = document.getElementsByName("checkbox");
for (var i=0; i<aa.length; i++){
result+=parseFloat((aa[i]).value);
}
document.form1.txt.value+=result;
window.open("Second.html");
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="checkbox" name="checkbox" value="1" id="checkbox" />
<input type="checkbox" name="checkbox" value="2" id="checkbox" />
<input type="button" value="btn" name="btn" onClick="checkAll()">
</form>
</body>
</head>
</html> 展开
展开全部
以下代码已经测试通过:
-------------first.html--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>first.html</title>
</head>
<body>
<script language="javascript" >
function Post()
{
//单个值 Read.htm?username=baobao;
//多全值 Read.htm?username=baobao&sex=male;
url = "second.html?username="+escape(document.all.username.value);
url += "&sex=" + escape(document.all.sex.value);
location.href=url;
}
</script>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="username">
<input type="text" name="sex">
<input type="button" onclick="Post()" value="Post">
</form>
</body>
</html>
-------------second.html--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>second.html</title>
</head>
<body>
<script language="javascript" >
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
{
var str = url.substr(1) //去掉?号
strs = str.split("&");
for(var i=0;i<strs.length;i++)
{
Request[strs[i ].split("=")[0]]=unescape(strs[ i].split("=")[1]);
}
}
alert("从first.html传过来的你输入的username:"+Request["username"])
alert("从first.html传过来的你输入的sex:"+Request["sex"])
</script>
</body>
</html>
-------------first.html--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>first.html</title>
</head>
<body>
<script language="javascript" >
function Post()
{
//单个值 Read.htm?username=baobao;
//多全值 Read.htm?username=baobao&sex=male;
url = "second.html?username="+escape(document.all.username.value);
url += "&sex=" + escape(document.all.sex.value);
location.href=url;
}
</script>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="username">
<input type="text" name="sex">
<input type="button" onclick="Post()" value="Post">
</form>
</body>
</html>
-------------second.html--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>second.html</title>
</head>
<body>
<script language="javascript" >
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
{
var str = url.substr(1) //去掉?号
strs = str.split("&");
for(var i=0;i<strs.length;i++)
{
Request[strs[i ].split("=")[0]]=unescape(strs[ i].split("=")[1]);
}
}
alert("从first.html传过来的你输入的username:"+Request["username"])
alert("从first.html传过来的你输入的sex:"+Request["sex"])
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-11-23
展开全部
为这两个都是静态页
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询