简体   繁体   English

PHP中的Echo Javascript文件

[英]Echo Javascript File in PHP

I am trying to echo out a .js file within a head tag with php. 我试图用php在head标签内回显.js文件。 The css file is working properly, however the js file isn't getting included. css文件运行正常,但是未包含js文件。 Here is what I have: 这是我所拥有的:

echo '<head>';
echo '<link rel="stylesheet" type="text/css" href="systemframe.css"/>';
echo '<script type="text/javascript" src="mainmenu.js"></script>';
echo '</head>';
echo '<form>';
echo '<body>';
...
echo '</body>';
echo '</form>';

I verified that the js file is good by manually placing it in the head tag of the index.html file. 我通过手动将js文件放在index.html文件的head标记中来验证它是好的。 The js file is located in the same folder as all of the other files, so there are no file directory levels. js文件与所有其他文件位于同一文件夹中,因此没有文件目录级别。 My goal is to dynamically add js files to the head of the website through php. 我的目标是通过php将js文件动态添加到网站的头部。 I saw other similar examples, so I am a bit confused why it is not working. 我看到了其他类似的例子,所以我有点困惑为什么它不起作用。

It should be something like 应该是这样的

echo '<head>';
echo '<link rel="stylesheet" type="test/css" href="systemframe.css"/>';
echo '<script type="text/javascript" src="mainmenu.js"></script>';
echo '</head>';

echo '<body>';
echo '<form>'; <------
...
echo '</form>';<------
echo '</body>';

Your form tag should come inside the body tag, not outside. 您的表单标签应位于正文标签内部,而不是外部。

Check whether you have JS error on your console(Developer tools). 检查控制台上是否有JS错误(开发人员工具)。 Make sure that JS is attached correctly. 确保正确连接了JS。

One last thing type="test/css" should be type="text/css" in 最后一件事情type="test/css"应该是type="text/css"

<link rel="stylesheet" type="test/css" href="systemframe.css"/>
                               ^------------------- should be text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM