简体   繁体   English

如何将 Javascript 链接到动态网站?

[英]How to link Javascript to a dynamic website?

I am having trouble linking a javascript file to a dynamic website i made through php.我无法将 javascript 文件链接到我通过 php 创建的动态网站。 My file structure is simply just:我的文件结构只是:

index .php, css folder (which is working correctly), jscript folder (does not work) and a pages folder (has all my pages) index .php、 css文件夹(工作正常)、 jscript文件夹(不起作用)和pages文件夹(包含我所有的页面)

My pages are simple just我的页面很简单

header .php, registrationContent .php and footer .php页眉.php、 registrationContent .php 和页脚.php

My index just includes all 3 php and it works perfectly fine.我的索引只包含所有 3 个 php,它运行得非常好。 My problem is no matter what I do, whether inline, or soft coded javascripting it does not work.我的问题是无论我做什么,无论是内联还是软编码的 javascripting,它都不起作用。 I am certain my syntax in the javascript is fine, its just the linking.我确信我在 javascript 中的语法很好,它只是链接。

My header:我的标题:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Safe Drive Website</title>
        <link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
        <link href="css/regStyle.css" rel="stylesheet" type="text/css" />
        <script src="jscript/javascripts.js" type="text/javascript"></script>
    </head>
    <body>
        <div class="topBar" id="topBar"><a href=""><input type="Submit" value="Contact Us" class="topNavButton"/></a></div>
        <div id="bannerText"><h1 class="mainHeader">SafeDrive</h1><h2 class="subHeader">Developer's Tool</h2></div>

I close the tags in the footer.php我关闭了footer.php中的标签

Javascript files are included directly in your html page. Javascript 文件直接包含在您的 html 页面中。 use the following line in your html page:在您的 html 页面中使用以下行:

<html>
<head>
    <script type="text/javascript" src="path/to/your/javascript/file.js"></script>
</head>
...

This is probably uncommon, but I thought of answering my own question because I found a solution, so that anyone else having the same problem could try mine.这可能不常见,但我想回答我自己的问题,因为我找到了一个解决方案,这样其他有同样问题的人都可以试试我的。

Basically, it was loaded, the only problem was that the javascript functions weren't loaded and so to do that, i had to add:基本上,它被加载了,唯一的问题是 javascript 函数没有加载,所以要做到这一点,我不得不添加:

window.onload = myJscriptFunction();

on any tag (body, footer etc. refer to w3schools for that information)在任何标签上(正文、页脚等。有关该信息,请参阅 w3schools)

I do hope this helps anyone facing the same problem ^_^希望对遇到同样问题的朋友有所帮助^_^

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

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