2011-12-14 60 views
0

重新加载页面后,此代码按预期工作 - javascript工作并打开一个弹出窗口。但是,当使用AJAX更改ajaxUpdatable的内容时,它不起作用。我如何“重新绑定”或在这里为我的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

我只想把这两行成一个函数并调用它,每当内容被改变。 – 2011-12-14 09:16:18

+0

嗯..那么谁应该叫eauth功能? – 2011-12-14 09:17:46

回答

0

试试这个

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