Uncaught TypeError: Object [object Object] has no method 'on'

前端 未结 4 864
你的背包
你的背包 2020-12-03 03:14

Can anyone help me to figure this out ?

When I use the latest (or a newish) version of jQuery, the small script below works fine. However, when I use older versions

相关标签:
4条回答
  • 2020-12-03 03:25

    You could use delegate(), for example:

    $("table").delegate("td", "click", function() {
      $(this).toggleClass("chosen");
    });
    

    This is equivalent to the following code written using on():

    $("table").on("click", "td", function() {
      $(this).toggleClass("chosen");
    });
    
    0 讨论(0)
  • 2020-12-03 03:26

    You must use bind instead of on, as on was only introduced in jQuery 1.7.

    $(document).ready(function () {
        $(".theImage").bind("click", function(){
            // In the event clicked, find image, fade slowly to .01 opacity
            $(this).find("img").fadeTo("slow", .01).end()
            // Then, of siblings, find all images and fade slowly to 100% opacity
            .siblings().find("img").fadeTo("slow", 1);           
        })
    })
    
    0 讨论(0)
  • 2020-12-03 03:34

    Change the on function to bind:

    .children().on("click",function()
    to
    .children().bind("click",function()

    0 讨论(0)
  • 2020-12-03 03:36

    You must use jQuery version 1.7+ to use on(). bind() is deprecated.

    0 讨论(0)
提交回复
热议问题