javascript jQuery 错误类型错误:$.event.handle 未定义

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

jQuery error TypeError: $.event.handle is undefined

javascriptjqueryruntime-errorjquery-masonry

提问by justnajm

I am using latest jQuery for jQuery.masonry its throwing following error: on line 47 in jquery-1.9.1.min.js

我正在为 jQuery.masonry 使用最新的 jQuery,它抛出以下错误:在 jquery-1.9.1.min.js 中的第 47 行

TypeError: $.event.handle is undefined

if any one is having same error ?

如果有人有同样的错误?

MyCode:

我的代码:

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/scripts/jquery-1.9.1.min.js"></script>
<script language="javascript" src="http://masonry.desandro.com/jquery.masonry.min.js"></script>
<script src="http://masonry.desandro.com/js/jquery.infinitescroll.min.js"></script>
<script>
  $(function(){

    var $container = $('#content');

    $container.imagesLoaded(function(){
      $container.masonry({
        itemSelector: '.post',
        isAnimated: true
      });
    });

    $container.infinitescroll({
      navSelector  : '.wp-pagenavi',    // selector for the paged navigation 
      nextSelector : '.wp-pagenavi a',  // selector for the NEXT link (to page 2)
      itemSelector : '.post',     // selector for all items you'll retrieve
      loading: {
          finishedMsg: 'No more pages to load.',
          img: 'http://i.imgur.com/6RMhx.gif'
        }
      },
      // trigger Masonry as a callback
      function( newElements ) {
        // hide new items while they are loading
        var $newElems = $( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
          // show elems now they're ready
          $newElems.animate({ opacity: 1 });
          $container.masonry( 'appended', $newElems, true ); 
        });
      }
    );

  });
</script>

回答by dwaddell

The function has been deprecated: http://jquery.com/upgrade-guide/1.9/#other-undocumented-properties-and-methods

该功能已被弃用:http: //jquery.com/upgrade-guide/1.9/#other-undocumented-properties-and-methods

You can use $.event.dispatch instead.

您可以使用 $.event.dispatch 代替。

In addition or alternatively to using the dispatch function you can add the Migrate plugin, http://blog.jquery.com/2013/05/01/jquery-migrate-1-2-0-released/, which will add back in $.event.handle so you able to fix the code without breaking the application.

除了或替代使用调度功能,您还可以添加 Migrate 插件http://blog.jquery.com/2013/05/01/jquery-migrate-1-2-0-released/,它将添加回$.event.handle 以便您能够在不破坏应用程序的情况下修复代码。

回答by Eric Martins

You are trying to use :

您正在尝试使用:

var $newElems = $( newElements ).css({ opacity: 0 });

as an element :

作为一个元素:

$newElems.imagesLoaded

Maybe this is the problem.

也许这就是问题所在。

A solution would be :

一个解决方案是:

 var $newElems = $( newElements );
 $newElems.css({ opacity: 0 });