jquery - Uncaught TypeError: $(...) is not a function - 当自调用函数位于脚本底部时
问题描述
代码片段是较大代码的可重现部分。在这里,如果我在底部编写自调用函数,它会给我“Uncaught TypeError: $(...) is not a function”,但如果我将它移到顶部,它会起作用。谁能帮我理解为什么会出现这个错误。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning</title>
<link rel="stylesheet" href="./style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(function() {
$(window).scroll(function(){
var height = $(window).height();
var scrollTop = $(window).scrollTop();
$('.status').html(scrollTop)
});
});
(function(a){
console.log(a);
}("sometext"));
</script>
</head>
<body>
<div class="status"></div>
</body>
</html>
解决方案
推荐阅读
- macos - 为什么 nwjs 更新程序不在 macOS 上工作?
- wifi - ESP32 - 网状网络连接时 esp-idf Wifi 扫描
- node.js - 在链中查找自签名证书
- delphi - 跨表单传递变量
- visual-studio-code - 如何删除不必要的 VsCode 终端
- android - 未能将价值纳入日志消息?Kotlin - Firebase
- android - CodePush React Native 在 versionName 上引发错误
- c++ - 如何在 ncursesw 中使用和更新面板
- apache-spark - 如何在一定时间内运行 Spark 结构化流式传输作业?
- python - 如何使用 pytorch visdom 在同一窗口中绘制散点图和线图