弄了1个很简单的例子,我希望提交表单后,能在目标页面获取提交的name值,请大侠用get和post各举1个例子吧。
以下是代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
</head>
<body>
<form id="form1" action="TargetPage.htm">
Name:<input type="text" id="txtName" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
我希望提交的name值,显示在TargetPage.htm这个页面上,也就是说在TargetPage.htm获取提交的值。
以下是代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
</head>
<body>
<form id="form1" action="TargetPage.htm">
Name:<input type="text" id="txtName" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
我希望提交的name值,显示在TargetPage.htm这个页面上,也就是说在TargetPage.htm获取提交的值。
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function submitForm() {
var txtObj = document.getElementById("txtName");
if (txtObj.value == "") {
window.alert("Name is not null!");
return false;
}
var formObj = document.getElementById("formOne");
var a = "target.htm?name=" + txtObj.value;
formObj.action = "target.htm?name=" + txtObj.value;
return true;
}
</script>
</head>
<body>
<form id="formOne" action="" onsubmit="return submitForm();">
Name:<input type="text" id="txtName" />
<input type="submit" value="提交" />
</form>
</body>
</html>
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function submitForm() {
var txtObj = document.getElementById("txtName");
if (txtObj.value == "") {
window.alert("Name is not null!");
return false;
}
var formObj = document.getElementById("formOne");
formObj.action = "target.htm";
formOne.submit()
}
</script>
</head>
<body>
<form id="formOne" action="" onsubmit="submitForm();return false">
Name:<input type="text" id="txtName" />
<input type="submit" value="提交" />
</form>
</body>
</html>
get一般是通过url来传递 aaa.html?name=abc
alert(window.location.search);
这个和get/post没有什么关系 一般向服务器提交数据的时候才有意义
你这个只是普通的静态页面传值
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>1.html</title>
<script language="javascript" type="text/javascript">
function submitForm() {
var txtObj = document.getElementById("txtName");
if (txtObj.value == "") {
window.alert("Name is not null!");
}
var a = "target.htm?name=" + txtObj.value;
window.location.href = "2.html?name=" + txtObj.value;
}
</script>
</head>
<body>
Name:<input type="text" id="txtName" />
<input type="button" value="提交" onclick="submitForm()" />
</body>
</html><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>2.html</title>
<script language="javascript" type="text/javascript">
function GetRequest(){
var url=location.search;
var theRequest=new Object();
if(url.indexOf("?")!=-1){
var str=url.substr(1)+"&";
strs=str.spilt("&");
for(var i=0;i<strs.length;i++){
theRequest[strs[i].split("=")[0]]=unescape[strs[i].split("=")[1]]
}
}
return theRequest;
} </script>
</head>
<body>
Name:<input type="text" id="txtName" value="" />
<script language="javascript" type="text/javascript">
var Request=new Object();
Request=GetRequest();
var name=Request["name"]
document.getElementById("txtName").value=name
</script>
</body>
</html>