jQuery的错误类型错误:$ .event.handle是未定义(jQuery error Typ

2019-09-02 23:07发布

在jQuery的1.9.1.min.js在线47:我使用最新的jQuery的jQuery.masonry其投掷以下错误

TypeError: $.event.handle is undefined

如果任何一个是有同样的错误?

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>

Answer 1:

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

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

另外或可替换使用调度功能,您可以添加迁移插件, http://blog.jquery.com/2013/05/01/jquery-migrate-1-2-0-released/ ,这将在加回$ .event.handle所以你能够修复代码不会破坏应用程序。



Answer 2:

您正在尝试使用:

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

作为一个元素:

$newElems.imagesLoaded

也许这就是问题所在。

一个解决办法是:

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


文章来源: jQuery error TypeError: $.event.handle is undefined