我的问题是,当我在链接中使用哈希标签时,它只是将哈希附加到 url,而不是转到路由。例如/ToDo/public/offline2.html#test
。如果我留下 tag = ""
它确实会出于某种原因转到路由器。
我已经使用以下代码关闭了 jquery 移动路由器
<script type="text/javascript">
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
});
</script>
<script src="../js/jquery.mobile.js"></script>
<script src="../js/jquery.js"></script>
我的 html 代码非常基本
<p>go to <a href="#test" id="#test">test page</a></p>
所以我有一个单独的 js 文件,其中包含文件 test.js 中的 javascript 代码。这是主要代码
$(app.init)
app.init = function() {
console.log('start init')
router = new TestRouter();
console.log('end init')
}
var TestRouter = Backbone.Router.extend({
routes:{
"":"home",
"test":"test"
},
initialize: function(){ var self = this
_.bindAll(self) },
home: function(){
alert(name);
// $.mobile.changePage($('#home-page'), {changeHash:false});
},
test: function (name) {
alert(name);
// $.mobile.changePage($('#test-page'), {changeHash:false});
}
})
正如我所说,当我像这样设置标签时,代码适用于家庭
<a href="" data-icon="home">Home</a>
最佳答案
在 Backbone 开始监视 hashchange 事件之前,您需要调用 Backbone.history.start()。
app.init = function() {
console.log('start init')
router = new TestRouter();
Backbone.history.start();
console.log('end init')
}
关于javascript - 主干路由器监听器未命中哈希标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13101905/