如何以编程方式触发Bootstrap模式? [英] How can I trigger a Bootstrap modal programmatically?

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

问题描述

如果我去这里

http://getbootstrap.com/2.3.2/javascript.html#modals

然后点击启动演示模式它会完成预期的操作。我正在使用模式作为我的注册过程的一部分,并且涉及服务器端验证。如果有问题,我想将用户重定向到同一模式,并显示我的验证消息。目前我无法弄清楚除了来自用户的物理点击之外如何显示模态。如何以编程方式启动模型?

And click 'Launch demo modal' it does the expected thing. I'm using the modal as part of my signup process and there is server side validation involved. If there are problems I want to redirect the user to the same modal with my validation messages displayed. At the moment I can't figure out how to get the modal to display other than a physical click from the user. How can I launch the model programmatically?

推荐答案

为了手动显示模态弹出窗口,您必须执行此操作

In order to manually show the modal pop up you have to do this

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

您之前需要使用 show:false 所以直到你手动完成它才会显示。

You previously need to initialize it with show: false so it won't show until you manually do it.

$('#myModal').modal({ show: false})

其中 myModal 是模态容器的名称。

Where myModal is the name of the modal container.

这篇关于如何以编程方式触发Bootstrap模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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