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

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

问题描述

如果我去这里

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

然后点击Launch demo modal"它会做预期的事情.我在注册过程中使用模态,并且涉及服务器端验证.如果出现问题,我想将用户重定向到显示验证消息的相同模式.目前我不知道如何让模态显示,而不是来自用户的物理点击.如何以编程方式启动模型?

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 是模态容器的 id.

Where myModal is the id of the modal container.

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

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