我正在使用rails 5和bootstrap 4.我还安装了:gem'bootstrap','〜> 4.0.0.alpha6'
查看代码:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Automate your conditions
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">What do you want to optimize for?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<%= link_to 'Popularity', '#' %>
<%= link_to 'Inventory turns', '#' %>
<%= link_to 'Seasonality', '#' %>
<%= link_to 'Profitability', '#' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Javascript代码:
$('#myModal').modal();
如果我点击“自动化你的条件”按钮,则没有任何反应。
谢谢!
答案 0 :(得分:0)
data-target
属性必须引用单击按钮时要显示的模式div的id
。
您可以尝试使用相同的参考data-target
- id
设置两个属性:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Automate your conditions
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
...
</div>
此外,如果您设置$('#myModal').modal();
,模式将被解雇&#34;当页面加载时,您可以尝试评论该段代码。