twitter-bootstrap 未捕获的类型错误:$(...).modal 不是 Codeigniter 中的函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36909625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:52:34  来源:igfitidea点击:

Uncaught TypeError: $(...).modal is not a function in Codeigniter

javascriptjquerytwitter-bootstrapbootstrap-modal

提问by Rajan

Hi I am trying to load bootstrap modal on page load.

嗨,我正在尝试在页面加载时加载引导模式。

I have referred this links:

我已经提到了这个链接:

Modal error - Uncaught TypeError: undefined is not a function modal

模态错误 - 未捕获的类型错误:未定义不是模态函数

Bootstrap : TypeError: $(…).modal is not a function

Bootstrap : TypeError: $(...).modal 不是函数

TypeError: $(…).modal is not a function with bootstrap Modal

类型错误:$(...).modal 不是带有 bootstrap Modal 的函数

So As per them I arranged my scripts as:

因此,根据他们,我将脚本安排为:

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>    
<script src="<?php echo site_url('js/bootstrap.min.js'); ?>"></script>      
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="<?php echo site_url('assets/js/jquery-1.11.1.min.js');?>"></script>
<script src="<?php echo site_url('assets/js/jquery.backstretch.min.js');?>"></script>
<script src="<?php echo site_url('assets/js/retina-1.1.0.min.js');?>"></script>
<script src="<?php echo site_url('assets/js/scripts.js');?>"></script>

And My Modal code like this:

我的模态代码是这样的:

<div class="modal hide fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Subscribe our Newsletter</h4>
            </div>
            <div class="modal-body">
        <p>Subscribe to our mailing list to get the latest updates straight in your inbox.</p>
                <form>
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Name">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" placeholder="Email Address">
                    </div>
                    <button type="submit" class="btn btn-primary">Subscribe</button>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(window).load(function(){
        $('#myModal').modal('show');
    });
</script>

But I am still getting the error on my modal is not being loaded. What can be the possible solution to this? How should be my scripts called in correct way

但是我仍然收到我的模态没有被加载的错误。对此有什么可能的解决方案?我的脚本应该如何以正确的方式调用

error

错误

Console error

控制台错误

回答by Rory McCrossan

Note that although you include jQuery and jQueryUI, you then add another two versions of jQuery afterjQueryUI (4 in total) which then supercedes the jQueryUI methods. You only need a single reference to jQuery, so remove those extra ones. Try this:

请注意,虽然包括jQuery和jQueryUI的,你再加入jQuery的另两个版本jQueryUI的(4个),然后取代了jQueryUI的方法。您只需要一个对 jQuery 的引用,因此删除那些额外的引用。试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>    
<script src="<?php echo site_url('js/bootstrap.min.js'); ?>"></script> 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="<?php echo site_url('assets/js/jquery.backstretch.min.js');?>"></script>
<script src="<?php echo site_url('assets/js/retina-1.1.0.min.js');?>"></script>
<script src="<?php echo site_url('assets/js/scripts.js');?>"></script>

Also note that both jQueryUI and Bootstrap have methods named modal()and could be conflicting with each other. I would strongly recommend you use only one of those libraries. Personally I would suggest Bootstrap over jQueryUI.

另请注意,jQueryUI 和 Bootstrap 都有命名的方法,modal()并且可能会相互冲突。我强烈建议您只使用这些库中的一个。我个人建议 Bootstrap 优于 jQueryUI。

回答by rick

If you import bootstrap.min.js correctly you don't need jquery-ui.

如果正确导入 bootstrap.min.js,则不需要 jquery-ui。

In this fiddleyou can found a functionin version of your modal with only bootsrap dependencies

在这个小提琴中,您可以找到一个只有 bootsrap 依赖项的模态函数版本