如何使用jQuery打开Bootstrap模式窗口? [英] How to open a Bootstrap modal window using jQuery?

查看:157
本文介绍了如何使用jQuery打开Bootstrap模式窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Twitter Bootstrap modal window functionality. When someone clicks submit on my form, I want to show the modal window upon clicking the "submit button" in the form.

<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();
});


推荐答案

Bootstrap有一些可以手动调用的函数模态:

Bootstrap has a few functions that can be called manually on modals:

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

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

You can see more here: Bootstrap modal component

特别是方法部分

所以你需要改变:

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

to:

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

如果您想制作自己的自定义弹出窗口,这里是来自其他社区的推荐视频会员:

If you're looking to make a custom popup of your own, here's a suggested video from another community member:

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

这篇关于如何使用jQuery打开Bootstrap模式窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆