0

这是我为模拟我的问题而创建的两个文件。在我的 locahost 中打开 test.php 时:

本地主机/项目/test.php

所有事件都会触发两次,如附图所示 萤火虫截图 如何防止这种情况,因为它会影响我的模板。子文件中的所有 javascript 事件(这里由 test2.php 模拟)被触发两次。

测试.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"
?>
4

0 回答 0