首页 > 解决方案 > 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>

标签: javascriptjquery

解决方案


我最终解决了我自己的问题。感谢大家的快速响应和帮助。

最终的原因是我正在使用的全局“sidebar.html”确实包含一个 jquery slim 版本。删除后,一切正常。


推荐阅读