我正在使用Twitter引导模式窗口功能。当有人在我的表单上单击提交时,我想在单击表单中的“提交按钮”时显示模态窗口。

<form id="myform" class="form-wizard">
    <h2 class="form-wizard-heading">BootStap Wizard Form</h2>
    <input type="text" value=""/>
    <input type="submit"/>
</form>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>

jQuery:

$('#myform').on('submit', function(ev) {
    $('#my-modal').modal({
        show: 'false'
    }); 


    var data = $(this).serializeObject();
    json_data = JSON.stringify(data);
    $("#results").text(json_data); 
    $(".modal-body").text(json_data); 

    // $("#results").text(data);

    ev.preventDefault();
});

当前回答

试试这个

myModal1是modal的id

$('#myModal1').modal({ show: true });

其他回答

Bootstrap有一些可以在情态动词上手动调用的函数:

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');

你可以在这里看到更多:Bootstrap模态组件

特别是方法部分。

所以你需要改变:

$('#my-modal').modal({
    show: 'false'
}); 

to:

$('#myModal').modal('show'); 

如果你想制作一个自己的自定义弹出窗口,这里有一个来自其他社区成员的建议视频:

https://www.youtube.com/watch?v=zK4nXa84Km4

在调用函数时尝试使用jQuery而不是$ sign,它在我的情况下工作,如下所示。

jQuery.noConflict(); 
jQuery('#myModal').modal('show'); 

jQuery.noConflict ();因为当jQuery('#myModal').modal('show');不能工作,这是由于两次包含jQuery造成的。包括jQuery 2次使情态动词不能工作。在这种情况下它就能解决问题,在我的例子中它是重复的。

进一步你可以去这个链接

通过JQuery调用引导模型窗口不显示

点击这里查看完整的解决方案:

http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_modal_show&stacked=h

确保将库按所需的顺序放置以获得结果:

1-第一个bootstrap.min.css 2- jquery.min.js 3- bootstrap.min.js

(换句话说,jquery.min.js必须在bootstrap.min.js之前调用)

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script> 

 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<form id="myform" class="form-wizard">
    <h2 class="form-wizard-heading">BootStap Wizard Form</h2>
    <input type="text" value=""/>
    <input type="submit" id="submitButton"/>
</form>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>

您可以使用下面的代码启动模态。

$(document).ready(function(){
    $("#submitButton").click(function(){
        $("#myModal").modal();
    });
});

此外,您还可以使用via data属性

<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>

在这种特殊情况下,您不需要编写javascript。

你可以在这里看到更多:http://getbootstrap.com/2.3.2/javascript.html#modals