php 后退按钮的代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3659782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
code for back button
提问by tintincutes
I have a php code here and I would like to create a "back" href to get me back to where I was before. Here's what I have:
我这里有一个 php 代码,我想创建一个“返回”href,让我回到以前的位置。这是我所拥有的:
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
<html>
<head></head>
<body>
<?php
// get form selection
$day = $_GET['day'];
// check value and select appropriate item
if ($day == 1) {
$special = 'Chicken in oyster sauce';
}
elseif ($day == 2) {
$special = 'French onion soup';
}
elseif ($day == 3) {
$special = 'Pork chops with mashed potatoes and green salad';
}
else {
$special = 'Fish and chips';
}
?>
<h2>Today's special is:</h2>
<?php echo $special; ?>
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
</body>
</html>
Please help. Thanks in advance!
请帮忙。提前致谢!
回答by GSto
<button onclick="history.go(-1);">Back </button>
回答by davehauser
If you want to do it (what I think you are trying right now) then replace this line
如果你想这样做(我认为你现在正在尝试)然后替换这条线
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
with this
有了这个
<button type="button" onclick="history.back();">Back</button>
If you don't want to rely on JavaScript then you could get the HTTP_REFERER
variable an then provide it in a link like this:
如果您不想依赖 JavaScript,那么您可以获取该HTTP_REFERER
变量,然后在这样的链接中提供它:
<a href="<?php echo $_SERVER['HTTP_REFERER'] ?>">Back</a>
回答by Waqar
<a href="javascript:history.back(1)">Back</a>
this one (by Eiko) is perfect, use css to make a button of <a>
...
eg you can use this css class in <a>
as `
这个(由 Eiko 提供)是完美的,使用 css 制作一个按钮<a>
……例如,您可以将这个 css 类<a>
用作`
<a class=".back_button" href="javascript:history.back(1)">Back</a>`
.back_button {
display:block;
width:100px;
height:30px;
text-align:center;
background-color:yellow;
border:1px solid #000000;
}
回答by Eiko
You need to tell the browser you are using javascript:
您需要告诉浏览器您正在使用 javascript:
<a href="javascript:history.back(1)">Back</a>
Also, your input element seems out of place in your code.
此外,您的输入元素在您的代码中似乎不合适。
回答by Chris
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
Is invalid HTML due to the unclosed input
element.
由于未关闭的input
元素,是无效的 HTML 。
<a href="#" onclick="history.back(1);">"Back"</a>
is enough
足够
回答by pranav shinde
In my application,above javascript function didnt work,because i had many procrosses inside one page.so following code worked for me hope it helps you guys.
在我的应用程序中,上面的 javascript 函数不起作用,因为我在一页中有很多 procrosses。所以下面的代码对我有用,希望对你们有帮助。
function redirection()
{
<?php $send=$_SERVER['HTTP_REFERER'];?>
var redirect_to="<?php echo $send;?>";
window.location = redirect_to;
}
回答by James Baloyi
Basically my code sends data to the next page like so:
基本上我的代码将数据发送到下一页,如下所示:
**Referring Page**
$this = $_SERVER['PHP_SELF'];
echo "<a href='next_page.php?prev=$this'>Next Page</a>";
**Page with button**
$prev = $_GET['prev'];
echo "<a href='$prev'><button id='back'>Back</button></a>";