简体   繁体   English

通过JavaScript调用Bootstrap模式

[英]Calling Bootstrap modal via JavaScript

I have this javascript function: 我有这个javascript函数:

function doDelete()
{
    if (root === null) {alert("Tree is Empty!"); return;}
    var strKey = document.getElementById('deleteKey').value;
    if (strKey=="") {alert("Please provide key"); return;}
    if (isNaN(strKey)) {alert("Key must be numeric"); return;}
    root = myBPT.Delete(root, strKey);
    myBPT.print_tree(root);
}

How can I change the alert to call a bootstrap modal instead? 如何更改警报以调用引导程序模式?

This is my data-target... #printLeaves 这是我的数据目标... #printLeaves

The easiest way is not to use JavaScript at all to show the modal but just set the appropriate classes and data fields that allow Bootstrap to handle it. 最简单的方法是根本不使用JavaScript来显示模式,而只是设置允许Bootstrap处理的适当的类和数据字段。 Some examples are here . 这里有一些例子。 Basically, you need to wrap <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> around your modal, then have the button look like: 基本上,您需要将<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">包裹在模态周围,然后使按钮看起来像:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Launch modal
</button>

There's also an example further down if you want to trigger it with a non-button event, but then you do have to use JavaScript. 如果您想通过非按钮事件来触发它,那么还有另外一个示例,但是您必须使用JavaScript。 I haven't done it using a separate script myself (my use case was with a button), but the documentation says you just call: $('#myModal').modal(options) 我自己没有使用单独的脚本来完成此操作(我的用例带有一个按钮),但是文档说您只是在调用: $('#myModal').modal(options)

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

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