这是我为模拟我的问题而创建的两个文件。 在我的locahost中打开test.php时:
本地主机/凸出/ test.php的
所有事件都会被触发两次,如图所示 如何防止它影响我的模板。子文件中的所有javascript事件(此处由test2.php模拟)都会被触发两次。
test.php的
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
</head>
<body>
<?php include_once './test1.php'; ?>
</body>
</html>
test1.php
<script>
$(function(){
console.log("00");
});
jQuery(document).on("pagebeforechange", function(event) {
console.log(event);
});
jQuery(document).on("pagebeforecreate", function(event) {
console.log(event);
});
jQuery(document).on("pagebeforehide", function(event) {
console.log(event);
});
jQuery(document).on("pagebeforeload", function(event) {
console.log(event);
});
jQuery(document).on("pagebeforeshow", function(event) {
console.log(event);
});
jQuery(document).on("pagechange", function(event) {
console.log(event);
});
jQuery(document).on("pagecreate", function(event) {
console.log(event);
});
jQuery(document).on("pagehide", function(event) {
console.log(event);
});
jQuery(document).on("pageinit", function(event) {
console.log(event);
});
jQuery(document).on("pageload", function(event) {
console.log(event);
});
jQuery(document).on("pageremove", function(event) {
console.log(event);
});
jQuery(document).on("pageshow", function(event) {
console.log(event);
});
console.log("hello");
</script>
<?php
echo "hello"
?>