$(...).on 不是函数 - jQuery 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21625231/
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-27 01:38:44  来源:igfitidea点击:

$(...).on is not a function - jQuery Error

jqueryjquery-uidialog

提问by Hassan Sardar

I am using dialog box, which I am closing when a user click anywhere on page expect that dialog box.

我正在使用对话框,当用户单击页面上的任何地方期望该对话框时,我将关闭该对话框。

Here is my code:

这是我的代码:

$('body').on('click','.ui-widget-overlay',function()
{ 
    $('#myRateSettingsPopup').dialog('close'); 
}); 

Somehow its returning an error:

不知何故它返回一个错误:

$(...).on is not a function

$(...).on 不是函数

What is wrong with my code ?

我的代码有什么问题?

I am using jquery-1.6.1.min.js , but I cannot update it to the latest version. I am bound.

我正在使用 jquery-1.6.1.min.js ,但我无法将其更新到最新版本。我被束缚了。

Is there any other way to do this ?

有没有其他方法可以做到这一点?

回答by Anirudha Gupta

Method onwas introduced in jQuery version 1.7.

方法on是在 jQuery 1.7 版中引入的。

I think you have to upgrade your jQuery library to the newest version.

我认为您必须将 jQuery 库升级到最新版本。

Otherwise, you can use bind:

否则,您可以使用bind

$( ".ui-widget-overlay" ).bind( "click", function(e) {
    $('#myRateSettingsPopup').dialog('close');
    e.stopPropagation(); 
});

回答by Arun P Johny

The replacement for .on() in jQuery > 1.4.2 is delegate()

jQuery > 1.4.2 中 .on() 的替代品是delegate()

$('body').delegate('.ui-widget-overlay', 'click', function () {
    $('#myRateSettingsPopup').dialog('close');
});

回答by Михаил Зайков

$( ".close" ).bind( "click", function(e) {
$('#popup1').hide();
    e.stopPropagation(); 
});

jquery-1.7 jqueryui/1.8.2 perfect.

jquery-1.7 jqueryui/1.8.2 完美。

or your overlay

或者你的叠加

$( ".YOUR OVERLAY" ).bind( "click", function(e) {
$('#YOUR POPUP').hide();
   e.stopPropagation(); 
});

回答by Kalai

Try liveinstead of onits a jquery version problem

尝试live而不是on它的 jquery 版本问题

$('body').live('click','.ui-widget-overlay',function()
{ 
    $('#myRateSettingsPopup').dialog('close'); 
}); 

回答by Prashobh

As jquery 1.6.1 is not supporting onso you can use live

由于 jquery 1.6.1 不支持on所以你可以使用live

$('body').live('click','.ui-widget-overlay',function(event)
{ 
          event.stopPropagation();        
          $('#myRateSettingsPopup').dialog('close'); 

});