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

前端 未结 4 868
你的背包
你的背包 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");
    });
    

提交回复
热议问题