如何在不同的div类中使用相同的表单

时间:2019-04-21 18:56:41

标签: html bootstrap-4 carousel

我面临的问题是form会随着每张幻灯片的出现而不断重置。如何在滑块更改图像时保持内容保存?

.carousel-control-next-icon,
.carousel-control-prev-icon {
  background-color: black !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="//via.placeholder.com/350x150" id="jpg">
      <!--Login-->
      <form class="box" action="index.html" method="post" position="sticky">
        <h1>Login</h1>
        <input type="text" name="" placeholder="Username" required>
        <input type="password" name="" placeholder="Password" required>
        <input type="submit" value="Login">
        <img src="//via.placeholder.com/140x100" id="png">
      </form>
    </div>

    <div class="carousel-item">
      <img src="//via.placeholder.com/350x150" id="jpg">
      <!--Login-->
      <form class="box" action="index.html" method="post" position="sticky">
        <h1>Login</h1>
        <input type="text" name="" placeholder="Username" required>
        <input type="password" name="" placeholder="Password" required>
        <input type="submit" value="Login">
        <img src="//via.placeholder.com/140x100" id="png">
      </form>
    </div>

    <div class="carousel-item">
      <img src="//via.placeholder.com/350x150" id="jpg">
      <!--Login-->
      <form class="box" action="index.html" method="post" position="sticky">
        <h1>Login</h1>
        <input type="text" name="" placeholder="Username" required>
        <input type="password" name="" placeholder="Password" required>
        <input type="submit" value="Login">
        <img src="//via.placeholder.com/140x100" id="png">
      </form>
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

我不知道如何防止form随幻灯片的更改而重置。我对此很陌生,正在使用bootstrap。一些帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

我不太了解您的问题。我还很新,但是您的意思是说,如果您从网页切换到其他网页,或者您提交信息,该网页会重置?顺便说一句,为什么表单的动作是“ index.html”?您应该有一些代码来检查密码是否不匹配,电子邮件无效等,不是吗?为什么在同一页面上有多个登录表单?