我在名为myjs.js的文件中有以下var函数:
var myVar = {
test:function(message){
alert(message);
}
}
以下脚本嵌入在名为header.html:
的页面中的django include中<script src="{{ MEDIA }}js/thispage.js"></script>
然后我有一个html文件,其中包含名为main-include.html
的标题和内容{% include "header.html" %}
{% block content %}{% endblock %}
然后我有运行js的页面调用另一个文件中的javascript:
{% include "main-include.html" %}
<table>
<tr><td>Test</td></tr>
</table>
<script>
$(document).ready(function() {
myVar.test();
});
</script>
当我运行它时,我得到以下js错误:未捕获的ReferenceError:myVar未定义
答案 0 :(得分:0)
我认为问题是在浏览器上刷新几次以加载JS。