javascript - jquery load 不是点击事件中的函数
问题描述
我是 jquery 的初学者。我今天遇到了这个问题。真的希望有人可以提供帮助。
$('#lecture').on('click', function() {
$("#screen").load("lecture_page.html");
});
错误: course_page.js:7 Uncaught TypeError: $(...).load is not a function
然而,
$("#screen").load("lecture_page.html");
这条线自己工作。
我已经在 stackoverflow 上搜索了几个小时。我尝试了几种方法,例如:检查我的版本不是“苗条”,尝试使用 .on("load") 而不是 .load()...
忘了说:
$('#lecture').on('click', function() {
$("#screen").html("lecture_page.html");
});
如果我使用 .html() 方法而不是 .load(),它将正常运行并在正确的位置显示文本“lecture_page.html”。
解决了。 最终的原因是我使用的全局侧边栏确实包含一个纤薄的版本。 谢谢你们的快速反应。 这是我关于stackoverflow的第一个问题。体验非常好!
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
//alert('course page js connected');
$(function() {
$("#sidebar").load("sidebar.html");
});
$('#lecture').on('click', function() {
$("#screen").load("lecture_page.html");
});
//error : course_page.js:7 Uncaught TypeError: $(...).load is not a function
//$("#screen").load("lecture_page.html"); //this line works fine, however the above "load" cannot be recognized
//-------------------------------------------------------------------
//below is everything I have tried
// $("#lecture").click(function(e){
// //e.preventDefault();
// console.log("clicked");
// $("#screen").load("lecture_page.html");
// });
//$("#screen").load("lecture_page.html");
// $(document).on('click','#lecture',function(e){
// //e.preventDefault();
// console.log("clicked");
// $("#screen").load("lecture_page.html");
// });
</script>
解决方案
我最终解决了我自己的问题。感谢大家的快速响应和帮助。
最终的原因是我正在使用的全局“sidebar.html”确实包含一个 jquery slim 版本。删除后,一切正常。
推荐阅读
- haskell - 寻找功能相似的序列A
- scala - 在 scala 中使用模式匹配优化错误处理
- html - *ngFor 生成的 mat-button 专注于加载
- uima - uima ruta 在一个 ruta 规则中创建两个注释
- android - 带有 customadapter 的 ListView -> onclick 对话框
- java - Main.isLeapYear 的结果被忽略 - 为什么?
- tensorflow - 构建 tensorflow 单元测试的问题
- sql - 如果有任何类似条件的值,请选择所有值
- c++ - 如何清除 Arduino 中串行接口的字节?
- python - 使用 python 3.x 进行网络抓取,我使用 pytharm