javascript - 以正确格式包含在 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() {
控制台中没有任何显示,所以我现在有点迷茫。
解决方案
为什么你的控制台什么也没显示?
tester()
因为当文档准备好时你没有调用你的函数。- 您的文档就绪语法错误。
您需要的是,像这样编写真正的文档就绪语法,然后调用您的tester()
函数
$(document).ready(function(){
tester();
console.log('testing'); //call the console log manually when the document ready.
});
推荐阅读
- php - 如何调用自定义函数作为 filter_input() 函数的验证器参数?
- c - 如何在 C 中使用 scanf() 检查输入字符数组 (%s) 的长度
- javascript - Vue组件中未触发更改事件的Flickity
- kubernetes - 采用带有 operator-sdk 和基于 helm 的运营商的现有 helm 版本
- java - 如果用户在 Java 中没有输入任何内容怎么办
- anaconda - jupyter 笔记本“ConnectionRefusedError”
- javascript - Knex RAW MySQL 查询添加新行
- css - 如何在 react-native 中设置左侧的后退按钮样式?
- java - 在 Spring Boot 中工作时如何在 xml 定义中获取我的应用程序上下文
- string - 宏中可怕的复合引用