gpt4 book ai didi

javascript - 如何阻止页面之间简单的 javascript 冲突?

转载 作者:行者123 更新时间:2023-11-28 18:33:04 25 4
gpt4 key购买 nike

所以我有 2 个页面 top.php 和我的 Currentpage.php。首页有最新版本的Jquery和Bootstrap。当前页面有我还无法升级的代码。有没有办法在加载后停止 top.php Javascript 代码,然后加载 currentpage.php Javascript 代码?

top.php 有:

<html lang="en">
<head>
<!-- Bootstrap -->
<script src="../bootstrap/jquery/1.12.2/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="../bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<!-- some code here for top navigation -->

Currentpage.php 有这个:

<head>
<script type="style/js/jquery.form-2.47.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.autocomplete.js"></script>
<script src="style/js/jquery-ui-1.8.1.dialog.min.js"></script>
<script type="text/javascript" src="index.js"></script>

</head>
<body>
<?php
include "../includes/top.php";
?>
<!-- stop the top.php code here then load the current page Javascript code -->
</body>

最佳答案

我使用一个变量来告诉 top.php 不要加载 jQuery。

top.php:

<html lang="en">
<head>
<?php if (!isset($jquery_loaded)) { ?>
<!-- Bootstrap -->
<script src="../bootstrap/jquery/1.12.2/jquery.min.js"></script>
<?php } ?>

<!-- Bootstrap Core JavaScript -->
<script src="../bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<!-- some code here for top navigation -->

当前页面.php:

<head>
<script type="style/js/jquery.form-2.47.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.autocomplete.js"></script>
<script src="style/js/jquery-ui-1.8.1.dialog.min.js"></script>
<script type="text/javascript" src="index.js"></script>

</head>
<body>
<?php
$jquery_loaded = true;
include "../includes/top.php";
?>
<!-- stop the top.php code here then load the current page Javascript code -->
</body>

关于javascript - 如何阻止页面之间简单的 javascript 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37618129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com