html页面间的传值 第一个画面的标题为“TEST1.htm”,画面上有一个文本输入框和一个按钮,如果文本输入框填写了内容,按钮click 以后跳转到新画面“TEST2.htm”,网页上显示刚才文本框的内容。在线等。我是菜鸟。谢谢大侠了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 test1.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD><SCRIPT LANGUAGE="JavaScript"><!-- function openNew(){ window.open("test2.html","test2"); }//--></SCRIPT> <BODY> <INPUT TYPE="text" NAME="test1" ID="test1"> <INPUT TYPE="button" VALUE="OPEN" ONCLICK="openNew();"> </BODY></HTML>test2.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD><SCRIPT LANGUAGE="JavaScript"><!-- window.onload = function() { document.body.innerHTML = window.opener.document.getElementById("test1").value; }//--></SCRIPT> <BODY> </BODY></HTML> test1.html: <form action="test2.html" method="get"> <input name="te" tyope="text" /><input type="submit" value="提交" /> </from>test2.html: <script> onload = function() { //解析url获取参数,不过有局限,就是这个参数必须是在最后,而且前面不能有和这个参数名一样的字符串 var url = decodeURIComponent(window.location.href); var startInd = url.indexOf('='); var ind = url.substring(startInd).indexOf('te'); document.getElementById('result').innerHTML = url.substring(ind+startInd+2,url.length); }</script><div id="result"></div> <script> function jump(){ var txt=document.getElementById("txt").value; location.href="b.html?value="+txt; } </script><body> <input type="text" id="txt"><input type="button" value="跳转" onclick="jump()">b.html<script> window.onload=function(){ document.getElementById("txt").value=getdatafromStr(location.href,"value") } function getdatafromStr(str,name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = str.substr(str.indexOf("\?")+1).match(reg); if (r!=null) return unescape(r[2]); return null; }</script><body> 这是B画面 <input type="text" id="txt"> 1.htm代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD><script language="javascript">function test(){ var name=document.getElementById("id").value; self.location='2.htm'; document.cookie="name="+name;}</script> <BODY> <input type="text" id="id" name="name"> <input type="button" name="test" value="test" onclick="test();"> </BODY></HTML>2.htm代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD><script language="javascript">window.onload=function() { var name=document.cookie.split(";")[0].split("=")[1]; document.getElementById("la").childNodes[0].nodeValue=name;} </script> <BODY> <label id="la">test</label> </BODY></HTML> 哇,100分哦, 我也来个test1.htm<!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"><head> <title></title> <script language="javascript" type="text/javascript"> function Go() { var value = document.getElementById("tbValue").value; window.open("test2.htm?" + value); } </script></head><body>值:<input id="tbValue" type="text" value="abcd" /><input type="button" value="go" onclick="Go()" /></body></html>test2.htm<!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"><head> <title></title> <script language="javascript" type="text/javascript"> window.onload = function() { var tb = document.getElementById("tbGetValue"); //value的内容将为 ?abcd var value = window.location.search; tb.value = value.substr(1); //去掉问号 } </script></head><body> <input id="tbGetValue" type="text" /></body></html> up这个,不推荐使用其它的window.open,容易被浏览器拦截 但是用这种方法页面根本就没法跳转了。location.href="b.html?value="+txt;就是这句代码不起作用 IE6我用的window.location.href="b.html?value="+txt;alert(window.location.href)倒是可以获取到地址和参数的。就是页面不跳转。郁闷! a和b是分开的两个html.在b.html里的是我下面写的,a中是上面写的我的也是IE6,没什么问题的,可能是你什么地方没弄对 如何用extjs tree 动态获取xml文件 求源代码 100分,js怎么页面载入时select默认指定的option 子窗体如何提交父窗体的表单? jquery库版本问题 为何我的幻灯片广告上传后不显示? 求一个javascript的滚动公告版 如何获取一个对象的标签?例如<a...>或者<img...> 请教一个用js控制mediaplay的问题 ●Form中如何判断:用户两项中至少需要填写一项? 如何取得页面的所有框架? 我觉得不通顺啊 先发后等吧 下面的函数应该多次执行,什么因素引发呢?
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function openNew(){
window.open("test2.html","test2");
}
//-->
</SCRIPT>
<BODY>
<INPUT TYPE="text" NAME="test1" ID="test1">
<INPUT TYPE="button" VALUE="OPEN" ONCLICK="openNew();">
</BODY>
</HTML>test2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.onload = function() {
document.body.innerHTML = window.opener.document.getElementById("test1").value;
}
//-->
</SCRIPT>
<BODY>
</BODY>
</HTML>
<form action="test2.html" method="get">
<input name="te" tyope="text" /><input type="submit" value="提交" />
</from>
test2.html:
<script>
onload = function() {
//解析url获取参数,不过有局限,就是这个参数必须是在最后,而且前面不能有和这个参数名一样的字符串
var url = decodeURIComponent(window.location.href);
var startInd = url.indexOf('=');
var ind = url.substring(startInd).indexOf('te');
document.getElementById('result').innerHTML = url.substring(ind+startInd+2,url.length);
}
</script>
<div id="result"></div>
<script> function jump(){
var txt=document.getElementById("txt").value;
location.href="b.html?value="+txt;
}
</script>
<body>
<input type="text" id="txt"><input type="button" value="跳转" onclick="jump()">
b.html
<script>
window.onload=function(){
document.getElementById("txt").value=getdatafromStr(location.href,"value")
}
function getdatafromStr(str,name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = str.substr(str.indexOf("\?")+1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
</script>
<body>
这是B画面
<input type="text" id="txt">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script language="javascript">
function test()
{
var name=document.getElementById("id").value;
self.location='2.htm';
document.cookie="name="+name;
}
</script>
<BODY> <input type="text" id="id" name="name">
<input type="button" name="test" value="test" onclick="test();">
</BODY>
</HTML>
2.htm代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script language="javascript">
window.onload=function()
{
var name=document.cookie.split(";")[0].split("=")[1];
document.getElementById("la").childNodes[0].nodeValue=name;
}
</script>
<BODY>
<label id="la">test</label>
</BODY>
</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">
<head>
<title></title>
<script language="javascript" type="text/javascript">
function Go() {
var value = document.getElementById("tbValue").value;
window.open("test2.htm?" + value);
}
</script>
</head>
<body>
值:<input id="tbValue" type="text" value="abcd" />
<input type="button" value="go" onclick="Go()" />
</body>
</html>test2.htm
<!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">
<head>
<title></title>
<script language="javascript" type="text/javascript">
window.onload = function() {
var tb = document.getElementById("tbGetValue");
//value的内容将为 ?abcd
var value = window.location.search;
tb.value = value.substr(1); //去掉问号
}
</script>
</head>
<body>
<input id="tbGetValue" type="text" />
</body>
</html>
up这个,不推荐使用其它的window.open,容易被浏览器拦截
但是用这种方法页面根本就没法跳转了。location.href="b.html?value="+txt;
就是这句代码不起作用
alert(window.location.href)倒是可以获取到地址和参数的。
就是页面不跳转。郁闷!