后退按钮的代码怎么写?

发布于 2024-09-18 06:02:43 字数 895 浏览 5 评论 0原文

我这里有一个 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> 

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

一向肩并 2024-09-25 06:02:43
<button onclick="history.go(-1);">Back </button>
<button onclick="history.go(-1);">Back </button>
你又不是我 2024-09-25 06:02:43

如果你想这样做(我认为你现在正在尝试),那么用

<input type="submit" <a href="#" onclick="history.back();">"Back"</a>

这个

<button type="button" onclick="history.back();">Back</button>

替换这一行如果你不想依赖JavaScript,那么你可以获取HTTP_REFERER变量,然后提供它在这样的链接中:

<a href="<?php echo $_SERVER['HTTP_REFERER'] ?>">Back</a>

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:

<a href="<?php echo $_SERVER['HTTP_REFERER'] ?>">Back</a>
空城之時有危險 2024-09-25 06:02:43
<a href="javascript:history.back(1)">Back</a>

这个(by Eiko)很完美,用css做了一个按钮...
例如,您可以在
中使用此 css 类作为`

<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;
}
<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 `

<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;
}
情绪 2024-09-25 06:02:43

您需要告诉浏览器您正在使用 javascript:

<a href="javascript:history.back(1)">Back</a> 

此外,您的输入元素在代码中似乎不合适。

You need to tell the browser you are using javascript:

<a href="javascript:history.back(1)">Back</a> 

Also, your input element seems out of place in your code.

远昼 2024-09-25 06:02:43
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>

由于未封闭的 input 元素,HTML 无效。

<a href="#" onclick="history.back(1);">"Back"</a>

就足够了

<input type="submit" <a href="#" onclick="history.back();">"Back"</a>

Is invalid HTML due to the unclosed input element.

<a href="#" onclick="history.back(1);">"Back"</a>

is enough

亢潮 2024-09-25 06:02:43

在我的应用程序中,上面的 javascript 函数不起作用,因为我在一个页面中有很多 procrosses。所以下面的代码对我有用,希望它对你们有帮助。

  function redirection()
        {
           <?php $send=$_SERVER['HTTP_REFERER'];?> 
            var redirect_to="<?php echo $send;?>";             
            window.location = redirect_to;

        }

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.

  function redirection()
        {
           <?php $send=$_SERVER['HTTP_REFERER'];?> 
            var redirect_to="<?php echo $send;?>";             
            window.location = redirect_to;

        }
不美如何 2024-09-25 06:02:43

基本上我的代码将数据发送到下一页,如下所示:

**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>";

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>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文