简体   繁体   English

在onLoad上显示Bootstrap模式

[英]Show a Bootstrap Modal onLoad

Have a series of page.handlebars that load dynamically into a {{{body}}} of a main layout. 有一系列的page.handlebars动态加载到主布局的{{{body}}}。

On redirect of a page to certain pages, would like to show a Bootstrap Modal onLoad. 在将页面重定向到某些页面时,想要显示一个Bootstrap Modal onLoad。

This would need to be within the body of the page, and the modalID is loaded dynamically. 这需要在页面的主体内,并且动态加载modalID。

This would seem to be correct, but what needs to be tweaked for it to work? 这似乎是正确的,但需要调整什么才能起作用?

<script type="text/javascript">
  $(document).ready(function(){
    $('#{{activate.[0]}}').modal('show')
  });
</script>

This should work. 这应该工作。 I tried this. 我试过这个。

$('#multi-file-dropzone-js').modal('show');

You can either read the id of modal in your javascript directly from the model files and then use it to open the modal. 您可以直接从模型文件中读取javascript中的模态ID,然后使用它来打开模态。 Or you can render the id in some hidden div(using handlebar) and can read the contents of that div and open the modal. 或者你可以在一些隐藏的div(使用把手)中渲染id,并可以读取该div的内容并打开模态。

You can't use handlebar tags inside your js code. 你不能在你的js代码中使用把手标签。

Check out this fiddle: http://jsfiddle.net/CkAcL/ 看看这个小提琴: http//jsfiddle.net/CkAcL/

js JS

var source   = $("#a").html();
var template = Handlebars.compile(source);
var context = {modalid: "#mymodalid"};
var html    = template(context);

function openModal(){
 var mymodalid=$("#modalid").html();
    // use $(mymodalid).show();
}

//call openModal() inside your document.ready()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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