未捕获的TypeError:对象[对象对象]的属性'$'不是函数 - 导致这个的原因是什么?

时间:2013-05-07 17:00:13

标签: javascript jquery

我收到错误Uncaught TypeError: Property '$' of object [object Object] is not a function,我无法弄清楚原因

// document head
<script src="http://localhost/js/jquery-1.9.1.min.js"></script>
<script src="http://localhost/js/utils.js"></script>

// document body
<script type="text/javascript">
        $(document).ready(function() {
                courseActions.init();
        });
</script>

// utils.js
var courseActions = {
    init: function() {
        $('.js-add-course-item').click(function(e) {
            e.preventDefault();
            alert('it works');
        });
    },
};

// error on line 3 of utils.js
Uncaught TypeError: Property '$' of object [object Object] is not a function utils.js:3
courseActions.init


// I have also tried changing $ to jQuery, but this results in the same error
Uncaught TypeError: Property 'jQuery' of object [object Object] is not a function utils.js:3
courseActions.init

修改 为了排除utils文件的任何潜在问题,我已将其完全删除并将所有代码放入正文中。我仍然得到同样的错误:

// document head
<script src="http://localhost/js/jquery-1.9.1.min.js"></script>

// document body
<script type="text/javascript">
        $(document).ready(function() {
            $('.js-add-course-item').click(function(e) {
                e.preventDefault();
                alert('it works');
            });
        });
</script>

为什么错误会被$('.js-add-course-item').click(function(e)而不是$(document).ready(function()行抛出?两行都引用了$ ......到底是什么?

0 个答案:

没有答案