jQuery加载不是点击事件内部的功能

时间:2018-12-03 02:57:50

标签: javascript jquery

我是jquery的入门者。我今天遇到了这个问题真的希望有人能提供帮助。

$('#lecture').on('click', function() {
    $("#screen").load("lecture_page.html");
});
  

错误:course_page.js:7未捕获的TypeError:$(...)。load不是   功能

但是

$("#screen").load("lecture_page.html");

此行本身有效。

我已经通过搜索stackoverflow在此上花费了几个小时。我尝试了几种方法,例如:检查我的版本不是“ slim”,尝试了.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>

1 个答案:

答案 0 :(得分:0)

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

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