如何使用 jQuery 打开 Bootstrap 模式窗口?
[英] How to open a Bootstrap modal window using jQuery?
本文介绍了如何使用 jQuery 打开 Bootstrap 模式窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Twitter Bootstrap 模态窗口功能.当有人在我的表单上点击提交时,我想在点击表单中的提交按钮"时显示模态窗口.
<div class="modal-body"><p>一个精致的身体……</p>
<div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button><button class="btn btn-primary">保存更改</button>
jQuery:
$('#myform').on('submit', function(ev) {$('#my-modal').modal({显示:'假'});var data = $(this).serializeObject();json_data = JSON.stringify(data);$("#results").text(json_data);$(".modal-body").text(json_data);//$("#results").text(data);ev.preventDefault();});
解决方案
Bootstrap 有几个可以在模态上手动调用的函数:
$('#myModal').modal('toggle');$('#myModal').modal('show');$('#myModal').modal('隐藏');
您可以在此处查看更多信息:Bootstrap 模态组件
特别是方法部分.
所以你需要改变:
$('#my-modal').modal({显示:'假'});
到:
$('#myModal').modal('show');
如果您想制作自己的自定义弹出窗口,以下是来自其他社区成员的推荐视频:
https://www.youtube.com/watch?v=zK4nXa84Km4
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 has a few functions that can be called manually on modals:
$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');
You can see more here: Bootstrap modal component
Specifically the methods section.
So you would need to change:
$('#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屋!