单击后退按钮后显示表格 [英] Show form after click back button
问题描述
我使用jquery显示隐藏的表单.我想知道当用户单击Submit
然后按back button
时如何自动显示表单.我不希望用户单击后退按钮后再次单击New Account
来显示表单.
I use jquery to show hidden form. I want to know how I can automatically show form when user click Submit
and then press back button
. I don't want user to click New Account
again to show form after they click back button.
我目前有以下工作代码:
I have these working code currently:
<head>
<script src="https://code.jquery.com/jquery-latest.js">
</script>
<script type="text/javascript">
$(function() {
$('#register_link').click(function() {
$('#show_form').toggle();
return false;
});
});
</script>
</head>
<a href="http://www.google.com/">Google</a>
|
<a href="#" id="register_link">New Account</a>
<div id="show_form" style="display: none;">
<form id="register_form" method="post" action="verify.php">
Username
<inputname="username" id="username" type="text">
<br>
Email
<input name="email" id="email" type="email">
<br>
<input class="button_register" type="submit" value="Create New Account"
/>
</form>
</div>
示例: http://jsfiddle.net/n9uGH/17/
实际上有可能吗?预先感谢
Is it actually possible? Thanks in advance
推荐答案
可以通过多种方式来实现,但这取决于您的服务器端语言和/或托管环境.这是一种相当简单且被广泛接受的方法,可以满足您的目的.
There are various ways that this could be achieved, however this depends on your server-side language and or hosting environment. Here is a fairly simple widely accepted methodology that should serve your purpose.
这基于jQuery的Cookie库 https://github.com/carhartl/jquery-cookie
This is based on this cookie library for jQuery https://github.com/carhartl/jquery-cookie
使用Cookie,您可以在两个页面加载之间保留信息.
Using cookies you can persist the information between the two page loads.
因此,在您的表单页面上,您将执行以下操作
So on your form page you would do something like this
$(function() {
$('#register_link').click(function() {
$('#show_form').toggle();
return false;
});
if($.cookie('form_submitted')){
$('#show_form').toggle();
}
});
然后在提交表单后出现的页面上执行此操作
Then on the page which appears after submitting the form you can do this
$(function() {
$.cookie('form_submitted', 'yes');
});
这篇关于单击后退按钮后显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!