我正在尝试在同一页面上的多个按钮上打开一个模态。不幸的是,我无法想出办法。
我想在多个注册选项中打开一个模态,用户可以在模态和注册上填写表单。
使用当前代码,模态适用于第一个按钮,但不适用于页面上的其他按钮。 :(
有谁能告诉我这方面的解决方案?
这是我的代码
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModal">
Create an account
</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModal">
Sign Up Here
</button>
<!-- Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<div class="row">
<div class="col-sm-6 text-center col-xs-height">
<div class="signup-popup">
<h4>Signup Now</h4>
<input class="col-xs-12" type="text" name="username" placeholder="Email Address">
<input class="col-xs-12" type="password" name="password" placeholder="Password">
<input class="col-xs-12" type="password" name="confirmPassword" placeholder="Confirm Password">
<input class="btn btn-primary btn-filled col-xs-12" type="submit" value="Submit">
</div>
</div>
<div class="col-sm-6 col-xs-height">
<div class="signup-facebook">
<div class="signup-facebook-container">
<a class="btn btn-block btn-social btn-facebook signup-facebook-btn" href="#">
<i class="fa fa-facebook"></i> | Signup with Facebook
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
提前致谢!
答案 0 :(得分:3)
确保添加 bootstrap js , bootstrap css 和 jquery 。解决您的问题。 jsfiddle的例子。请看一看 JSFIDDLE示例。
创建一个帐户
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModal">
Sign Up Here
</button>
<!-- Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<div class="row">
<div class="col-sm-6 text-center col-xs-height">
<div class="signup-popup">
<h4>Signup Now</h4>
<input class="col-xs-12" type="text" name="username" placeholder="Email Address">
<input class="col-xs-12" type="password" name="password" placeholder="Password">
<input class="col-xs-12" type="password" name="confirmPassword" placeholder="Confirm Password">
<input class="btn btn-primary btn-filled col-xs-12" type="submit" value="Submit">
</div>
</div>
<div class="col-sm-6 col-xs-height">
<div class="signup-facebook">
<div class="signup-facebook-container">
<a class="btn btn-block btn-social btn-facebook signup-facebook-btn" href="#">
<i class="fa fa-facebook"></i> | Signup with Facebook
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
试试这个,
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".signupModal">
Create an account
</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".signupModal">
Sign Up Here
</button>
<!-- Modal -->
<div class="modal fade signupModal" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<div class="row">
<div class="col-sm-6 text-center col-xs-height">
<div class="signup-popup">
<h4>Signup Now</h4>
<input class="col-xs-12" type="text" name="username" placeholder="Email Address">
<input class="col-xs-12" type="password" name="password" placeholder="Password">
<input class="col-xs-12" type="password" name="confirmPassword" placeholder="Confirm Password">
<input class="btn btn-primary btn-filled col-xs-12" type="submit" value="Submit">
</div>
</div>
<div class="col-sm-6 col-xs-height">
<div class="signup-facebook">
<div class="signup-facebook-container">
<a class="btn btn-block btn-social btn-facebook signup-facebook-btn" href="#">
<i class="fa fa-facebook"></i> | Signup with Facebook
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<button class="btn" id="add-more">Click Me</button>
确保包含bootstrap.js和bootstrap.css