gpt4 book ai didi

php - 所需 php 中的 Javascript 文件不起作用,但直接在文件中可以

转载 作者:行者123 更新时间:2023-11-28 09:07:30 27 4
gpt4 key购买 nike

我有一个index.php文件,需要一个通用的head.php文件,head.php文件中有几个Javascript文件,当这样尝试时,代码在源代码中看起来很好,但文件却不是实际上对文档做任何事情。 (.css 文件工作正常)

如果 Javascript 文件直接放入 index.php(与需要 head.php 的头区域相同),即使源代码显示完全相同的代码,它们也可以正常工作。

是否有一个技巧可以使其正常工作,或者我是否必须手动将 Javascript 放入网站上的每个页面? (有很多,我希望能够使用单个 head.php,以防万一我想更新文件或添加脚本)

任何帮助将不胜感激!

以下是不同页面的一些代码供引用:

<小时/>

head.php

<link rel="stylesheet" type="text/css" href="style/main.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="include/alajax.js"></script>
<script type="text/javascript" src="include/jtip.js"></script>
<script type="text/javascript" src="include/jquery.timeago.js"></script>
<小时/>

index.php

<head>
<?php require_once 'site/head.php'; ?>
</head>
<小时/>

index.php(浏览器显示的源代码)

<head>
<!--require_once 'site/head.php';-->
<link rel="stylesheet" type="text/css" href="includes/fancy/fancy.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="include/alajax.js"></script>
<script type="text/javascript" src="include/jtip.js"></script>
<script type="text/javascript" src="include/jquery.timeago.js"></script>
<!-- end of head.php -->
</head>
<body>
<!-- Site that uses jquery and other functions in the included javascript that do not work with the files when included through a .php, though works fine if directly on the same page as the functions -->
<小时/>

编辑:(这是一个更充实的index.php,其中包含header.php和login.php)

index.php

<head>
<?php require_once 'site/head.php'; ?>
</head>
<body>
<div id="header">
<?php require 'site/header.php'; ?>
</div>
<div id="wrapper">
<div id="navbar">
<?php require 'site/navbar.php'; ?>
</div>
<div id="content">
<!-- Just basic php and html here, and some times that rely on jquery.timeago.js to calculate time, works fine when everything is loaded in head.php -->
</div>
</div>
</body>

header.php(不要与 head.php 混淆)

<div id="loginheader">
<img src="img/logo.png" width="200" height="100" alt="Logo" />
<?php
require 'login.php';
?>
</div>

login.php

<!--- Contains javascript that requires jquery (included in head.php) and alajax (also included in head.php) if jquery is loaded in here and not in head, the form works, but the times in index.php break. -->

最佳答案

大家好,我终于找到了答案,js 文件未加载的原因是我/您的其中一个 js 文件存在问题。所以请一一检查所有js文件,以确定损坏的文件。

我的案例的解释。

我已将所有 css 和 js 文件包含在名为 html_header.php 的文件中

<script type="text/javascript" src="../js/jquery-1.7.2.min.js"> </script>
<script type="text/javascript" src="../js/excanvas.js"> </script>
<script type="text/javascript" src="../js/jquery.flot.js"> </script>
<script type="text/javascript" src="../js/jquery.flot.stack.js"> </script>
<script type="text/javascript" src="../js/jquery.flot.pie.js"> </script>
<script type="text/javascript" src="../js/jquery.quicksand.js"> </script>
<script type="text/javascript" src="../js/jquery.easing.1.3.js"> </script>
<script type="text/javascript" src="../js/jquery.tipsy.js"> </script>
<script type="text/javascript" src="../js/cl_editor/jquery.cleditor.min.js"> </script>
<script type="text/javascript" src="../uploadify/swfobject.js"></script>
<script type="text/javascript" src="../uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript" src="../js/jquery.autogrowtextarea.js"></script>
<script type="text/javascript" src="../js/form_elements.js"></script>
<script type="text/javascript" src="../js/jquery.ui.core.js"></script>
<script type="text/javascript" src="../js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../js/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="../js/jquery.ui.slider.js"></script>
<script type="text/javascript" src="../js/jquery.ui.progressbar.js"></script>
<script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../js/jquery.ui.tabs.js"></script>
<script type="text/javascript" src="../js/jquery.ui.autocomplete.js"></script>
<script type="text/javascript" src="../js/jquery.ui.position.min.js"></script>
<script type="text/javascript" src="../js/fullcalendar.js"></script>
<script type="text/javascript" src="../js/gcal.js"></script>
<script type="text/javascript" src="../js/bootstrap-modal.js"></script>
<script type="text/javascript" src="../js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="../js/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="../js/highlight.js"></script>
<script type="text/javascript" src="../js/jq_tables/jquery.dataTables.js"></script>
<!--<script type="text/javascript" src="../js/main.js"> </script>-->
<script type="text/javascript" src="../js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../js/jquery.printElement.min.js"></script>
<script type="text/javascript" src="../js/addmethod.js"></script>

当我评论 main.js 时,问题解决了。在我上传 main.js 文件的新副本之后。

谢谢

关于php - 所需 php 中的 Javascript 文件不起作用,但直接在文件中可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16802749/

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