首页 > 解决方案 > 以正确格式包含在 html 中时,Javascript 文件不起作用

问题描述

我的 js 文件旁边的标题中包含 jquery,格式正确,但它似乎不想工作。

这是需要 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>

这是javascript文件的开头

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


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

控制台中没有任何显示,所以我现在有点迷茫。

标签: javascriptphphtml

解决方案


为什么你的控制台什么也没显示?

  1. tester()因为当文档准备好时你没有调用你的函数。
  2. 您的文档就绪语法错误。

您需要的是,像这样编写真正的文档就绪语法,然后调用您的tester()函数

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

推荐阅读