php - 避免返回到页面顶部

标签 php html

我希望当我按下提交按钮时,页面保持在当前位置,我知道必须使用它:

<form action="<?php echo $_SERVER['PHP_SELF'].'#ancre'.$i ?>" method="post"> 

<span id="#ancre"></span>

但我不知道定位在哪里,至少当我尝试时它不起作用。 我的代码:

<form action="<?php echo $_SERVER['PHP_SELF'].'#ancre2'.$i ?>" method="post">
                  <h1>
                      <label for="reponse">Votre r&eacuteponse :</label>
                      <input class="question" type="text" name="reponse" 
                       placeholder="Avec l'unit&eacute" size="10" maxlength="10" 
                       />
                      <input type="submit" name="valider2" value="V&#233rifier 
                      r&#233ponse" />
                      <?php
                      if(isset($_POST['valider2'])) {
                          $reponse = -1;
                          $personne=$_POST['reponse'];
                          if ($personne == $reponse) {
                              echo 'Bravo vous avez juste !';
                          }
                          else {
                              echo 'Vous avez faux, concentrez-vous';
                          }
                      }
                      ?>
                      <span id="#ancre2"></span>
                  </h1>
</form>

最佳答案

您可以添加 onSubmit="return false;"<form>元素。这将在提交时停止任何表单操作。

Fiddle

关于php - 避免返回到页面顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43719320/

相关文章:

jquery - 根据列表大小调整 Bootstrap 菜单多列的大小

html - html 图像的常见问题

php - 编辑现有查询以搜索时间是否在开始日期和结束日期之间

php - PayPal Chained Payment(钱不去二次)

php - 在 Windows 服务器上使用 mkdir 时权限被拒绝

html - 在 Django 的 TextField 中禁用 HTML 转义

php - 如何将产品描述(简短)添加到 woocommerce 中的悬停框?

php - 关于重构自定义路由场景的建议(Lithium Framework)

php - yII2:日期过滤器如何在 Gridview 中

html - div 中的响应式 UL 以填充空间