【发布时间】:2012-11-06 17:09:47
【问题描述】:
我有两个页面以单页模板的方式编写。
Login.html 在他的<head></head> 中有<script src="login.js" />,这就像:
$(document).on("pageinit", "#loginPage", function(){
$("#loginBtn").on("tap", function(){
// if you are already authenticate or login success...
$.mobile.changePage("Main.html");
});
});
Main.html 在他的<div data-role="page" id="main"></div> 中有<script src="main.js" />,这就像:
$(document).on("pageinit", "#main", function(){
//if not authenticated go to login
$.mobile.changePage("Login.html");
callJsonService();
$("#btnLogout").on("tap", function(){
//do logout operatio and go back to login
$.mobile.changePage("Login.html");
}).on("vmousedown", function(){
$(this).addClass("tapped");
}).on("vmouseup", function(){
$(this).removeClass("tapped");
});
如果您前后导航这两个页面,每次访问该页面时,与on() 绑定的事件都会被触发两次,然后是三次,然后是四次等等。
为什么会这样?是因为“pageinit”事件吗?还是把 main.js 放在 data-role=page 的 div 里面不正确?
【问题讨论】:
标签: jquery jquery-mobile ibm-mobilefirst jquery-events