我根本不懂JavaScript。Bootstrap文档说到
通过JavaScript调用modal: $('#myModal').modal(options)
我不知道如何在页面加载上调用这个。使用Bootstrap页面上提供的代码,我可以成功地在元素单击上调用模态,但我希望它立即在页面加载上加载。
我根本不懂JavaScript。Bootstrap文档说到
通过JavaScript调用modal: $('#myModal').modal(options)
我不知道如何在页面加载上调用这个。使用Bootstrap页面上提供的代码,我可以成功地在元素单击上调用模态,但我希望它立即在页面加载上加载。
当前回答
除了user2545728和Reft的答案,没有javascript,但与情态背景
添加3件事
一个在.modal类之前带有modal- background类的div Style ="display:block;"到.modal类 与.modal类一起淡出
例子
<div class="modal-backdrop in"></div>
<div class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="channelModal" style="display:block;">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="channelModal">Welcome!</h4>
</div>
<div class="modal-body" style="height:350px;">
How did you find us?
</div>
</div>
</div>
</div>
其他回答
您可以通过数据属性激活模态,而不需要编写任何JavaScript。
选项"show"设为true显示初始化时的模态:
<div class="modal fade" tabindex="-1" role="dialog" data-show="true"></div>
你不需要javascript来显示模态
最简单的方法是将"hide"替换为"in"
class="modal fade hide"
so
class="modal fade in"
你需要添加onclick = "$('.modal').hide()"按钮关闭;
PS:我认为最好的方法是添加jQuery脚本:
$('.modal').modal('show');
为了避免引导被否决并失去它的功能,只需创建一个常规的启动按钮,为它提供一个Id,然后使用jquery“点击它”,如下所示: 启动按钮:
<button type="button" id="btnAnouncement" class="btn btn-primary" data-toggle="modal" data-target="#modalAnouncement">
See what´s new!
</button>
jQuery触发器:
$(document).ready(function () {
$('#btnAnouncement').click();
)}
希望能有所帮助。干杯!
这里有一个解决方案[没有javascript初始化!]
我找不到一个例子,没有初始化你的模式与javascript, $('#myModal').modal('show'),所以这里有一个建议,你可以实现它没有javascript延迟页面加载。
用类和样式编辑你的modal容器div:
<div class="modal in" id="MyModal" tabindex="-1" role="dialog" style=" font - family:宋体;padding-right: 17 px;" >
Edit your body with class and style: <body class="modal-open" style="padding-right:17px;"> Add modal-backdrop div <div class="modal-backdrop in"></div> Add script $(document).ready(function() { $('body').css('padding-right', '0px'); $('body').removeClass('modal-open'); $('.modal-backdrop').remove(); $('#MyModal').modal('show'); }); What will happen is that the html for your modal will be loaded on page load without any javascript, (no delay). At this point you can't close the modal, so that is why we have the document.ready script, to load the modal properly when everything is loaded. We will actually remove the custom code and then initialize the modal, (again), with the .modal('show').
在bootstrap 3中,你只需要通过js初始化模态,如果在页面加载的时刻,模态标记在页面中,模态就会显示出来。
如果你想防止这种情况,可以在初始化模态的地方使用show: false选项。就像这样: $ (' .modal ')。Modal ({show: false})