2013-04-24 68 views
2

我使用jquery ui tab加載一個HTML,在該HTML我有一個方法。我怎樣才能從JQuery的UI標籤是由AJAX加載這個方法

$("#tabs").tabs({    
       beforeLoad: function (event, ui) { 
        ui.jqXHR.error(function() { 
         ui.panel.html(
          "Couldn't load this tab. We'll try to fix this as soon as possible. " + 
          "If this wouldn't be a demo."); 
        }); 
        ui.jqXHR.success(function() { 
         alertMe() 
        }); 
       } 
      }); 

<div id="tabs" style="height: 100%"> 
     <ul> 
      <li><a href="Map.html">Tab 1</a></li> 
     </ul> 
</div> 

在map.html中我有alertMe方法。這裏顯示alertMe是未定義的。

回答

3

當服務器成功返回響應時,但在任何標籤頁呈現邏輯發生之前(如將html/js添加到頁面中)時,會調用jqXHR'success'。因此,一個更好的解決辦法是使用標籤控件的加載方法處理呼叫:

$('tab's).tabs({ 
    beforeLoad: ... 
    load: function() { 
     alertMe(); // Global JS on loaded fragment will be available on page now 
    } 
}); 

API文檔:http://api.jqueryui.com/tabs/#event-load