在我的站点中,我看到在浏览器的前进按钮选择期间调用了 pageinit。这个对吗。这不会绑定注册的事件两次。
第一个.html
<!DOCTYPE HTML>
<html>
<head>
<title>Test1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="../scripts/common.js"></script>
</head>
<body>
<div data-role="page" id="first">
<h1 style="background: red">Swipe 1</h1>
<a href="second.html">Click</a>
</div>
</body>
</html>
第二个.html
<!DOCTYPE html>
<html>
<head>
<title>Test2</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="../scripts/common.js"></script>
</head>
<body>
<div data-role="page" id="second">
<div data-role="header">
<h1>jQuery Mobile</h1>
</div>
<div data-role="content">
<a href="third.html">Click</a>
</div>
<div data-role="footer">
<h4>www.jboss.org/developer</h4>
</div>
</div>
</body>
</html>
第三个.html
<!DOCTYPE html>
<html>
<head>
<title>jQuery Mobile Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body>
<div data-role="page" id="third">
<div data-role="header">
<h1>jQuery Mobile</h1>
</div>
<div data-role="content">
<ul id="listOfItems" data-role="listview" data-inset="true" data-filter="true">
<li><a href="">One</a>
</li>
<li><a href="">Two</a>
</li>
<li><a href="">Three</a>
</li>
</ul>
</div>
<div data-role="footer">
<h4>www.jboss.org/developer</h4>
</div>
</div>
</body>
</html>
common.js
$(document).on('pageinit', "#first", function (event) {
console.log("first");
});
$(document).on('pageinit', "#second", function (event) {
console.log("second");
});
$(document).on('pageinit', "#third", function (event) {
console.log("third");
});
你能检查一下上面的代码,让我知道为什么每次都调用 pageinit。