Javascript window.location.href在第二时间内不工作
我有以下代码Javascript window.location.href在第二时间内不工作,javascript,jquery,Javascript,Jquery,我有以下代码 file_1.js demo : function(){ var idList = []; idList.push(1); window.location.href = "#/transferToReport/" + idList; return false; } file_2.js window.Router = Backbone.Router .extend({ routes : { "transferToReport/:fileIdList" :
file_1.js
demo : function(){
var idList = [];
idList.push(1);
window.location.href = "#/transferToReport/" + idList;
return false;
}
file_2.js
window.Router = Backbone.Router
.extend({
routes : {
"transferToReport/:fileIdList" : "transferToReport",
},
transferToReport : function(fileIdList) {
console.log("print")
}
});
templateLoader.load([
..//load some templates
], function() {
location.hash = '';
app = new Router();
Backbone.history.start();
});
我想从文件_1.js中的demo()函数调用文件_2.js中的函数transferToReport()
上面的代码是第一次执行的,但之后就不再执行了。
我做错了什么?这似乎是一个显而易见的答案,如果您已经想到了这一点,那么很抱歉,您是否在重定向到的页面上包含了重定向功能?嗨,您能解释一下什么不起作用吗?比如,是页面没有向上滚动到那个div吗?嗨,关于文件2中的语法有一些问题。例如,
传输到报告
:函数()
。你能检查一下并发回(只是为了确定)。@tyskr现在更正了代码对不起。还有一件事:app=newrouter();Backbone.history.start()代码>也需要在扩展之外声明。我认为,一旦使用主干路由器,理想的导航方式是使用:。还有一些选项(触发器,替换
)。