2011-12-14 4 views
0

페이지를 다시로드 한 후이 코드가 예상대로 작동합니다. javascript가 작동하고 팝업이 열립니다. 그러나 ajaxUpdatable의 내용이 AJAX를 사용하여 변경되면 작동하지 않습니다. 내 eauth 기능을 위해 .live()를 "다시 바인딩"하거나 만들 수있는 방법은 무엇입니까?AJAX 후에 JavaScript를 작동시키는 방법?

$("a.google").eauth({"popup":{"width":880,"height":520},"id":"google"}); 

전체 페이지는 여기입니다.

<div class="ajaxUpdatable"> 
    <a class="direct auth-link google" href="/coverication/? 
r=site/login&amp;service=google">Google</a> 
<a class="direct auth-link yandex" href="/coverication/?r=site/login&amp;service=yandex">Яндекс 
</div> 

<script type="text/javascript"> 
jQuery(function($) { 
    var popup; 

    $.fn.eauth = function(options) { 
     options = $.extend({ 
      id: '', 
      popup: { 
       width: 450, 
       height: 380 
      } 
     }, options); 

     return this.each(function() { 
      var el = $(this); 
      el.live('click', function() { 
         if (popup !== undefined) 
          popup.close(); 

         var url = this.href + (this.href.indexOf('?') >= 0 ? '&' : '?') + 'js'; 
         /*var remember = $(this).parents('.auth-services').parent().find('.auth-services-rememberme'); 
         if (remember.size() > 0 && remember.find('input').is(':checked')) 
          url += '&remember';*/ 

         var centerWidth = ($(window).width() - options.popup.width)/2; 
         var centerHeight = ($(window).height() - options.popup.height)/2; 

         popup = window.open(url, "yii_eauth_popup", "width=" + options.popup.width + ",height=" + options.popup.height + ",left=" + centerWidth + ",top=" + centerHeight + ",resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes"); 
         popup.focus(); 

         return false; 
        }); 
     }); 
    }; 
}); 

$("a.google").eauth({"popup":{"width":880,"height":520},"id":"google"}); 
$("a.yandex").eauth({"popup":{"width":900,"height":550},"id":"yandex"}); 
</script> 
+1

난 그냥 함수에 다음 두 줄을 넣어 내용이 변경 될 때마다 호출 할보십시오. –

+0

음 ... 그렇다면 누가 eauth 기능을 호출해야합니까? –

+0

Ajax 호출을 통해 내용이 변경 될 때 실행되는 콜백 함수입니다. –

답변

0

는이

$("a.google").live("eauth", function({ 
    "popup": { "width": 880, "height": 520 }, 
    "id": "google" 
}); 
+1

'eauth'는 트리거되는 이벤트입니까? –

+0

이미 시도했습니다. 라이브의 첫 번째 매개 변수는 이벤트 여야합니다. 하지만 내 것은 기능입니다. 내 원래 게시물에 live()를 말하면 내 기능에 대해 live()와 같은 의미로 업데이트 된 내용의 Ajax를 "다시로드"합니다. –

관련 문제