重新初始化jQuerytools覆盖在ajax加载的元素上

Reinitialize jQuerytools Overlay on ajax loaded element

本文关键字:加载 元素 ajax 初始化 jQuerytools 覆盖      更新时间:2023-09-26

我正在尝试在新的ajax加载元素上重新初始化Overlay。这是我的代码:

  $('input.search-files').keyup(function(event){
      if( event.keyCode == 13 ) {
          $.ajax({
          type: "GET",
          url: ...,
          dataType: "html",
          data: {...},
          beforeSend: function(){ 
              $('.tr-documento').fadeOut('fast', function(){ $(this).remove(); });
              $('.table-content').find('.table-loader').show(); 
          },
          success: function(data) {
              if( $(data).filter('tr').length == 0 ){ 
                  $('.table-loader').before( '<tr class="tr-documento"><td colspan="10">Non ci sono</td></tr>' ); 
              } else{
                  $('.table-loader').before( $(data).filter('tr') );
              }        
             $('.table-content').find('.table-loader').hide();
             $("table.table-content").tablesorter({headers: { 0: { sorter: false }, 6: { sorter: false },7: { sorter: false },8: { sorter: false },9: { sorter: false } } });
             reInitializeAjaxed();
             $(".modifica-file[rel]").overlay();
        }
      });
    }
  });

此功能在按下"ENTER"键时触发。一切都很好,桌上分拣机第一次点击就可以工作。jQuerytools覆盖事件,只在第二次点击"ENTER"时绑定。

有人知道这个问题吗?有没有一种方法可以"实时"覆盖事件而不重新初始化每个ajax调用?我试过这个:

$(document).delegate('.modifica-file[rel]', 'load', function(){ $(".modifica-file[rel]").overlay(); });

但不起作用。。

我认为没有打开,因为覆盖层只初始化而没有激发。

您可以将加载属性设置为true,如:

$(".modifica-file[rel]").overlay({load: true});

或者使用load方法手动发射覆盖层:

$(".modifica-file[rel]").data("overlay").load();

文档:http://jquerytools.org/documentation/overlay/

示例:http://jquerytools.org/demos/overlay/trigger.html

我在这里找到了解决方案:http://flash.flowplayer.org/forum/tools/40/21252

这个链接上有很多解决方案,我使用的是:

$(".modifica-file[rel]").live('click', function () {
 $(this).overlay().load();
 $(this).overlay().load();
 return false;
});

我认为这是一个相当肮脏的解决方案…$。最新的jQuery版本不再支持live()方法。。。但我使用的是1.7.2,它运行良好!

我把这个片段添加到SUCCESS AJAX回调的末尾。