我有一个问题,也许你可以帮助我。我有一个页面(index.php):...
<head>
<script src="site/js/mootools-core.js" /></script>
<script src="site/js/mootools-more.js" /></script>
<script type="text/javascript" src="site/js/router.js" /></script>
<script type="text/javascript" src="site/js/app.js" /></script>
</head>
<body></body>
...
router.js 项目:https ://github.com/xrado/Router/blob/master/Demo/index.html
应用程序.js:
window.addEvent('domready',function(){
var Core = {
loadScript:function(url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" || script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
}
} else { //Others
script.onload = function(){
callback();
}
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
}
var router = new Router({
routes: {
'' : 'index',
'#!index' : 'index'
},
onReady: function(){
Core.init(); // Render body here ... working!
},
onIndex: function() {
Core.loadScript("index.js", function(){
index.init(); // ReferenceError: index is not defined
console.log('Index loaded...');
});
}
});
});
这是我的外部 index.js:
var index = {
init : function(){
$('div_content').set('html', index.render());
},
render: function() {
...
}
}
如果我尝试加载我的页面,我会收到此错误:
ReferenceError:索引未定义 index.init();
两周找不到错误!谢谢。