简体   繁体   中英

I tried to use bootstrap modal class to make a popup signup form but popup doesn't work

I tried to use bootstrap modal class to make a popup signup form and when i press the signup button window just fade and reload that's it. popup doesn't work. I'm using bootstrap 3.3.6. please help.

this is the sign up button code:

<form class="navbar-form navbar-right">
  <button type="submit" class="btn btn-default navbar-btn sign" data-toggle="modal" data-target="#signupForm">Sign up</button>
</form>

I am using the signup button inside a nav (navbar-inverse).

this is the popup form code:

<div class="modal fade" id="signupForm" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="">
          <span>&times;</span>
        </button>
        <h4 class="modal-title">Sign Up</h4>
      </div>

      <div class="modal-body">
        <form class="form-horizontal">
          <div class="form-group">
            <label class="col-md-4 col-md-offset-1">User Name :</label>
            <div class="col-md-5">
              <input type="text" class="form-control input-sm">
            </div>
          </div>

          <div class="form-group">
            <label class="col-md-4 col-md-offset-1">Email :</label>
            <div class="col-md-5">
              <input type="email" class="form-control input-sm">
            </div>
          </div>

          <div class="form-group">
            <label class="col-md-4 col-md-offset-1">Password :</label>
            <div class="col-md-5">
              <input type="password" class="form-control input-sm">
            </div>
          </div>

          <div class="form-group">
            <label class="col-md-4 col-md-offset-1">Confirm Password :</label>
            <div class="col-md-5">
              <input type="password" class="form-control input-sm">
            </div>
          </div>

          <div class="form-group">
            <div class="col-md-2 col-md-offset-8">
              <input type="submit" class="btn btn-success" value="submit">
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

I coded this popup form code below the signup button code and that means it's inside the navbar

Please check this:

I have created a JS Fiddle and it is working fine here.

   ----  https://jsfiddle.net/DTcHh/19115/

You must include Bootstrap js and css file to your project in order to make it work.

Here your working code

 <html> <head> <script src="https://code.jquery.com/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> </head> <body> <form class="navbar-form navbar-right"> <button type="submit" class="btn btn-default navbar-btn sign" data-toggle="modal" data-target="#signupForm">Sign up</button> </form> <div class="modal fade" id="signupForm" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label=""> <span>&times;</span> </button> <h4 class="modal-title">Sign Up</h4> </div> <div class="modal-body"> <form class="form-horizontal"> <div class="form-group"> <label class="col-md-4 col-md-offset-1">User Name :</label> <div class="col-md-5"> <input type="text" class="form-control input-sm"> </div> </div> <div class="form-group"> <label class="col-md-4 col-md-offset-1">Email :</label> <div class="col-md-5"> <input type="email" class="form-control input-sm"> </div> </div> <div class="form-group"> <label class="col-md-4 col-md-offset-1">Password :</label> <div class="col-md-5"> <input type="password" class="form-control input-sm"> </div> </div> <div class="form-group"> <label class="col-md-4 col-md-offset-1">Confirm Password :</label> <div class="col-md-5"> <input type="password" class="form-control input-sm"> </div> </div> <div class="form-group"> <div class="col-md-2 col-md-offset-8"> <input type="submit" class="btn btn-success" value="submit"> </div> </div> </form> </div> </div> </div> </div> </body> </html> 

I fixed the problem. I find out the cause is that button type should be button not submit . I changed the button type to button then it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM