Javascript 提交HTML表单后如何返回上一页

Javascript 提交HTML表单后如何返回上一页,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我的HTML代码包含两个HTML表单和两个按钮: 一个用于提交,一个用于取消(基本上回到上一页)。我想做的是在我点击SUBMIT按钮并提交表单之后,执行与cancel按钮相同的操作(返回上一页)。 问题是,我无法指定我希望它返回的页面,因为此页面将在许多页面中使用,因此它将是动态的 <div data-role="page" id="customer" data="Page" data-expired="true" data-theme="c"> <div data-

我的HTML代码包含两个HTML表单和两个按钮: 一个用于提交,一个用于取消(基本上回到上一页)。我想做的是在我点击SUBMIT按钮并提交表单之后,执行与cancel按钮相同的操作(返回上一页)。 问题是,我无法指定我希望它返回的页面,因为此页面将在许多页面中使用,因此它将是动态的

<div data-role="page" id="customer" data="Page" data-expired="true" data-theme="c">

    <div data-role="content" data="customers" data-key="id" data-params="item:itemid">

        <div align="left">
            <h3 style="margin:0px">Customer Profile</h3>
        </div>

        <br/>

        <div class="popup-hrule">
            <div data-role="collapsible" data-collapsed="false" data-collapsed-icon="false" data-theme="a">
                <h3>Customer</h3>
                <form id="submit-edit-customer" method="post" data-formaction="process">


                            <label for="customer_name">Customer</label>
                            <input type="text" name="customer_name" id="customer_name" data-item=":customer_name">
                        </div>
                        <div class="ui-block-b">
                            <label for="name">Primary Contact</label>
                            <input type="text" name="name" id="name" value="no valid name"
                                   data-item=":name">
                        </div>

                </form>
            </div>

            <div data-role="collapsible" data-collapsed-icon="false" data-theme="a">
                <h3>Billing</h3>
                <form id="submit-edit-customer" method="post" data-formaction="process">


                            <label for="customer_name">Customer</label>
                            <input type="text" name="customer_name" id="customer_name" data-item=":customer_name">
                        </div>
                        <div class="ui-block-b">
                            <label for="name">Primary Contact</label>
                            <input type="text" name="name" id="name"
                                   data-item=":name">
                        </div>

                </form>
            </div>

        </div>
        <a id="createeditcancel" data-role="button" data-inline="true" href="#" data-rel="back">Cancel</a>
        <a id="submit-edit-customer-btn" data-role="button" data-inline="true" data-theme="a">Save</a>

    </div>
</div>

客户资料

顾客 顾客 主要联系人 演员表 顾客 主要联系人 拯救
我的问题是,有没有简单的方法可以做到这一点,而不用在onclick事件中编写大量javascript代码


谢谢

在操作页面或控制器上尝试添加以下内容:

$(document).ready(function(){
document.location = 'url' // the path to your homepage
});

非常简单,您只需将href更改为上一页的url即可:

<a id="createeditcancel" data-role="button" data-inline="true" href="YOUR_URL_HERE" data-rel="back">Cancel</a>
由于它是动态的,您只需从与其他信息相同的位置获取返回URL,然后执行以下操作:

header("Location:" + URL);

我不知道我可以做到这一点,但我尝试了,它的工作! 我在提交按钮中添加了:
data rel=“back”

像这样:

<a id="submit-edit-customer-btn" data-role="button" data-inline="true" data-rel="back" data-theme="a">Save</a>
保存

用于重定向到JavaScript中您可以使用的其他页面

window.location = "http://www.yoururl.com";
添加到按钮onclick=“location.href='www.yoursite.com'

你在哪里处理你的表单?php文件

php中的其他选项

    if (isset($_POST['submitform']))
    {   
    ?>
<script type="text/javascript">
window.location = "http://www.google.com/";
</script>      
    <?php
    }
if(isset($\u POST['submitform']))
{   
?>
window.location=”http://www.google.com/";

使用
文档。参考人

var cancel=function(){
window.location.href=document.referer;
};

您是否尝试将上一页的url添加到“取消和保存”标记中的href?href=“thelastpage.html”应该可以。这是jQuery Mobile的吗?谢谢你的回答。对不起,我刚才说的是提交按钮,我是说在我提交表单后,我想回到上一页。我表单中的取消按钮可以正常工作,返回到上一页。你好,索尔,我下面的回答不是你想要的oking for?谢谢Leo的回答,但我自己刚刚找到了答案。无论如何,谢谢。好的,请发布你的答案并将其标记为正确,或者投票选择一个对你有用的答案,以防其他用户遇到这个问题,他真的找到了答案…我还没有看到文档。referer解决方案。快速且肮脏,我喜欢它。谢谢!
    if (isset($_POST['submitform']))
    {   
    ?>
<script type="text/javascript">
window.location = "http://www.google.com/";
</script>      
    <?php
    }
<form action="demo_form.asp" onsubmit="myFunction()">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>


<script>
    function myFunction() {
 location.href = 'www.yoursite.com';
}
    </script>