简体   繁体   English

找不到以前导入的js模块

[英]can't find previously imported js module

I'm facing an error where a jQuery code can't find a previously imported module. 我遇到一个错误,其中jQuery代码找不到以前导入的模块。

I'm using jQuery and tag-it ( https://github.com/aehlke/tag-it/blob/master/README.markdown ) 我正在使用jQuery和tag-it( https://github.com/aehlke/tag-it/blob/master/README.markdown

I import the scripts in this order: 我按以下顺序导入脚本:

<script src="js/vendor/jquery.min.js" type="text/javascript"></script>
<script src="js/vendor/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/vendor/jquery-ui-touch-punch.min.js" type="text/javascript"></script>
<script src="js/vendor/tag-it.min.js" type="text/javascript"></script>
<script src="js/tags.js" type="text/javascript"></script>

tag-it.min.js is the Tag-It provided js module and tags.js is my custom module. tag-it.min.js是Tag-It提供的js模块,而tags.js是我的自定义模块。

tags.js is as follows: tags.js如下:

$(document).ready(function(){

var $available_tags = $('#user_tags').val().split(",").slice(0, -1);


$('#tags').tagit({
    fieldName: "tags",
    availableTags: $available_tags,
    placeholderText: "Enter Tags",
    beforeTagAdded: function(event, ui){
        var tag = ui.tag.text().slice(0, -1);
        if($.inArray( tag, $('#user_tags').val().split(",") ) == -1){
            $.get("/tags/add?tag=" + tag, function(data){
                if(!data.error){
                    $("#user_tags").val( $("#user_tags").val() + tag + ",");
                } else {
                    console.log("Eror", data);
                    return false;
                }
            });
        }
    },
    showAutocompleteOnFocus: true
});


});

The error is in tags.js at line 6: 错误在第6行的tags.js中:

$('#tags').tagit({

Undefined error: tagit does not exist. 未定义的错误:tagit不存在。 http://puu.sh/gCVUh/2d792035f6.png http://puu.sh/gCVUh/2d792035f6.png

How is this possible? 这怎么可能? The js loading order is fine and yet it seems not to recognice it. js加载顺序很好,但似乎无法识别。

Thanks in advance, if more information is needed ask for it and I'll update the thread. 预先感谢,如果需要更多信息,请提出要求,我将更新该线程。

Ok I found out why it wasn't working. 好的,我发现了为什么它不起作用。

I just noticed that I duplicated jQuery script import some lines after these imports. 我只是注意到,在这些导入之后,我重复了jQuery脚本导入的某些行。

This was resseting jQuery enviroment and therefore, tag-it was removed from it. 这是在重置jQuery环境,因此将其标记删除。

Hope this helps someone in a future and thanks for the help! 希望这对以后的人有所帮助,并感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM