弄了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获取提交的值。

解决方案 »

  1.   

    如果你提交的页面是普通的HTM页面的话,就不存在GET,POST的方法,因为GET和POST是在服务器端进行执行的,如果你要在HTM页面通过JS来接收前一个页面传过来的值的话,一般的做法是把Name字段作为URL字符串传给TargetPage.htm页面,也就相当于"http://..../TargetPage.htm?name=youname",然后你在TargetPage.htm这个页面中增加一个JS函数对URL进行解析,从而得到name字段的值。
      

  2.   

    我这样写了个,但目标页面获取的NULL....继续求解!<html xmlns="http://www.w3.org/1999/xhtml">
    <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>
      

  3.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <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>
      

  4.   

    post是通过提交来传递数据  一般就是form表单提交
    get一般是通过url来传递   aaa.html?name=abc
      

  5.   

    你目标页面是怎么提取内容的?
    alert(window.location.search);
      

  6.   

    form的action=‘a.html?a=123’提交后,window.location.search是获取不到参数的!
      

  7.   

    在targetpage.html里面自己用js 拆析window.location.href
    这个和get/post没有什么关系 一般向服务器提交数据的时候才有意义
    你这个只是普通的静态页面传值
      

  8.   


    <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>