シングルページテンプレートの方法で2ページを書いています。
Login.html に<script src="login.js" />
は彼が<head></head>
あり、これは次のようなものです。
$(document).on("pageinit", "#loginPage", function(){
$("#loginBtn").on("tap", function(){
// if you are already authenticate or login success...
$.mobile.changePage("Main.html");
});
});
Main.html は<script src="main.js" />
彼の中に<div data-role="page" id="main"></div>
あり、これは次のようなものです:
$(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");
});
これらの 2 つのページを前後に移動すると、そのページにアクセスするたびに、バインドされたイベントon()
が 2 回、次に 3 回、次に 4 回、というように発生します。
なぜこうなった?「pageinit」イベントが原因ですか?または、main.js を data-role=page で div 内に配置するのは正しくありませんか?