TypeError: jQuery(...).on 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18958775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:51:06  来源:igfitidea点击:

TypeError: jQuery(...).on is not a function

javascriptjquerytypeerror

提问by Jeremy

Guys I have this function from a wordpress plugin:

伙计们,我从 wordpress 插件中获得了这个功能:

jQuery( '#widget-twitter-__i__-username' ).on( 'change', function() {
  jQuery('#widget-twitter-__i__-list' ).val(0);
});

jQuery( '#widget-twitter-__i__-list' ).on( 'change', function() {
  jQuery('#widget-twitter-__i__-username' ).val(0);
});

The error I am getting is:

我得到的错误是:

TypeError: jQuery(...).on is not a function

When I click that error on the error console, I get to the above code.

当我在错误控制台上单击该错误时,我会看到上面的代码。

And I was wondering what would be the way to address this issue.

我想知道解决这个问题的方法是什么。

回答by Anton

If your jQuery version is under 1.7 i'd suggest using .delegate()or .live()or update your jQuery to the latest version

如果您的jQuery的版本是1.7下我建议使用.delegate().live()或更新的jQuery到最新版本

jQuery( '#widget-twitter-__i__-list' ).delegate(

or

或者

jQuery( '#widget-twitter-__i__-list' ).live(