首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:$(...).gridstack不是函数#709

TypeError:$(...).gridstack不是函数#709
EN

Stack Overflow用户
提问于 2017-07-10 15:30:55
回答 1查看 3K关注 0票数 1

这是我的脚本序列:

代码语言:javascript
复制
src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"
src="../dist/gridstack.js"
src="gridstack.js"
src="../dist/gridstack.min.js"
href="../dist/gridstack.css"
href="../dist/gridstack.min.css"

这是我的JavaScript代码,我在其中使用了网格堆栈函数,但它显示了错误。请检查脚本和JavaScript文件的顺序。

代码语言:javascript
复制
    $(function () {
 alert("1");
    $('.grid-stack').gridstack({
        animate: true,
        auto: true,
        width: 12,
        float: true,
        vertical_margin: 0,
        always_show_resize_handle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
        resizable: {
            handles: 'e, se, s, sw, w'
        }   
    });

    $('.grid-stack-placeholder').remove();

    this.grid = $('.grid-stack').data('gridstack');

    this.add_widget = function(){
     alert("OK");

        var id = getRandomInt(1111,9999);

        var el = $.parseHTML("<div><div class=\"grid-stack-item-content\" data-id=\""+id+"\"/><div/>");
        this.grid.add_widget(el, 0, 0, 6, 5, true);

        $('.grid-stack-item-content[data-id="'+id+'"]').append('<span class="fa fa-times remove-widget"> </span><span class="fa fa-pencil select-use"></span>  </span><span class="fa fa-plus add-nested-widget-box"></span> ');

    }.bind(this);

    this.clear_grid = function () {
        this.grid.remove_all();
    }.bind(this);

    $('.clear-customization, .customize-pages-list li').click(this.clear_grid); 
    $('.add-widget-box').click(this.add_widget);

});

$('body').on('click', '.remove-widget', function(){

    var grid = $('.grid-stack').data('gridstack');

    grid.remove_widget($(this).parents().eq(1));

});


function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
EN

回答 1

Stack Overflow用户

发布于 2017-07-10 15:47:45

将css放在顶部,而不是js文件。

代码语言:javascript
复制
 href="../dist/gridstack.css"

在最后

代码语言:javascript
复制
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" 
src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"
src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"
src="../dist/gridstack.js"

从您的js中删除这些gridstack.min.js,因为您正在使用它的开发版本。

即使这不起作用,也可以试试这个

代码语言:javascript
复制
<script>
$.noConflict();


  $('.grid-stack').gridstack({
        animate: true,
        auto: true,
        width: 12,
        float: true,
        vertical_margin: 0,
        always_show_resize_handle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
        resizable: {
            handles: 'e, se, s, sw, w'
        }   
    });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45006135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档