Bootstrap $('#myModal')。modal('show')不起作用 [英] Bootstrap $('#myModal').modal('show') is not working

查看:515
本文介绍了Bootstrap $('#myModal')。modal('show')不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么,但所有的模态功能都不适用于我。
我检查了版本和负载它们没问题。

I'm not sure why but all the modal functions are not working with me. I checked the version and the load they are fine.

我不断收到此错误消息:

I keep getting this error message:

未捕获TypeError:$(.. 。)。modal不是函数

我已经找到了另一种隐藏的隐藏。
而不是:

for the hide I already found an alternative. instead of:

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

我用过这个:

$('#myModal .close').click();

它完美无缺。

问题现在是节目

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

我也试过了两次

$('#myModal').modal("toggle");

并且:

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

但不幸的是,它们都没有工作。

but unfortunately none of them is working.

这里是html代码 - 当点击按钮时,我会做一些验证并处理来自Web服务的json数据,如果它成功,那么我想要显示我的模态 - 一切都在工作,除了节目。

Here html code -when the button is clicked I will do some verification and handle a json data from the web service if it succeed then I want show my modal- everything is working except the show.

 <button type="button" id="creatNewAcount" class="btn btn-default" data-toggle="modal">Sign up</button>

如果有任何其他我想知道的话。

if there's any alternative I would like to know it.

推荐答案

此类问题的最常见原因是

Most common reason for such problems are


1.如果已定义jquery库不止一次。

1.If you have defined the jquery library more than once.



<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

    <div class="modal fade" id="myModal" aria-hidden="true">
    ...
    ...
    </div>

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

引导程序库应用于第一个jquery库但是当你重新加载jquery库时,原始的引导程序加载丢失(模态函数在引导程序中)。

The bootstrap library gets applied to the first jquery library but when you reload the jquery library, the original bootstrap load is lost(Modal function is in bootstrap).


2.请将JavaScript代码包装在内

2.Please wrap your JavaScript code inside



$(document).ready(function(){});




3.请检查模态的id是否相同

3.Please check if the id of the modal is same

作为您为组件定义的那个(同时检查相同ID的重复)。

as the one you have defined for the component(Also check for duplication's of same id ).

这篇关于Bootstrap $('#myModal')。modal('show')不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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