[英]TypeError: EventList is not a constructor in one place, in another code works
奇怪的情况是,我在django(1.8)应用中具有js功能。 在一个地方一切正常,但在另一个地方却出现错误:
Uncaught TypeError: EventList is not a constructor
js文件中的代码:
var EventList=function(){};
EventList.prototype.init=function(){this.$eventslist=$(".event-list")
...
当我尝试使用eventList = EventList();
调用时eventList = EventList();
我收到消息: Uncaught TypeError: EventList is not a function
HTML文件中的代码,在js代码块中:
<script src="{% static 'js/event_list.min.js' %}" type="text/javascript"></script>
<script type="text/javascript">
eventList = new EventList();
eventList.init();
</script>
你有没有尝试过
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() { var
var eventList = new EventList();
eventList.init();
});
</script>
也许您需要等待文档准备就绪,或者您需要“更改” eventList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.