简体   繁体   中英

Javascript file not functioning when included in html with correct format

I have jquery included in the header alongside my js file and the format is correct, but it just doesn't seem to want to work.

Here is the header for the storepage.php file that needs the js file.

<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="Styles/CSS/design.css">
    <title>GET YOUR KEYS HERE</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/storePage.js"></script>
    <script type="text/javascript" src="Scripts/addTag.js"></script>
</head>

<body>

and here is the beginning of the javascript file

function tester() {
    console.log("Checking document status...");
}


console.log("Checking document status...");
$(document).ready(function() {

Nothing shows up in console, so I am a bit lost at the moment.

You should be calling your function inside your document.ready() method to make it run after the document is loaded:

function tester() {
    console.log("Checking document status...")
}

$(document).ready(function(){
  tester()
});

Why nothing show in your console?

  1. Cause you not call your tester() function when the document is ready.
  2. Your document ready syntax is wrong.

What you need is, write true document ready syntax like this, and call your tester() function

$(document).ready(function(){
  tester();
  console.log('testing'); //call the console log manually when the document ready.
});

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