简体   繁体   English

包含正确格式的html中的Javascript文件不起作用

[英]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. 我的js文件旁边的标题中包含了jquery,格式正确,但是似乎并不想工作。

Here is the header for the storepage.php file that needs the js file. 这是需要js文件的storepage.php文件的头。

<!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 这是javascript文件的开头

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: 您应该在document.ready()方法内调用函数,以使其在加载文档后运行:

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. 因为在文档准备好后您没有调用tester()函数。
  2. Your document ready syntax is wrong. 您的文档就绪语法错误。

What you need is, write true document ready syntax like this, and call your tester() function 您需要的是,编写像这样的真正文档就绪语法,然后调用tester()函数

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

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

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