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

标签 javascript php jquery html twitter-bootstrap

所以我有 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/

相关文章:

php - 从wordpress数据库中选择类:

javascript - Jekyll 静态页面的主干路由/历史记录问题

javascript - Angular 尝试读取服务中的属性

javascript - AngularJS - 没有错误但没有 View

javascript - 在调用自定义模态的 javascript 变量之前添加简单的 7 秒延迟

jquery - 以 Ruby on Rails 形式获取 HTML5 范围值

jquery - 如何在不卡住网页的情况下同步调用ajax

javascript - 最小的 CommonJS 实现

javascript - 如何在脚本中使用 session ?

php - 如何获取数组中某些数组的值之和?