简体   繁体   中英

Javascript files not loading for page

I have a fairly simple HTML file:

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>deploy.rb</title>
        <script src="test.js" type="text/javascript"></script>
        <script src="OtherScript.js" type="text/javascript"></script>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        body
    </body>
</html>

test.js looks like this:

window.onload = function () { alert("It's loaded!") }

Can someone tell me why I don't get an alert when the page loads? (and why none of the functions in OtherScript.js are executing)

The full contents of the html file can be found here, if it helps.

I'm an idiot. OtherScript.js also used window.onload . I consolidated both scripts into the same file, and now it works file.

you might check the directory structure. The code looks fine to me, so if I had to guess the .js files are not being found correctly. If they're in the same directory as the HTML file you might try appending ./ to the beginning of the filename.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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