2011-06-05 25 views
4

我從HTML文件附加HTML標籤到正文使用jQuery.After我加載html標籤我加載JS文件,做html上的東西tags.jQuery不適用於加載的html,但當我在頁面jQuery上靜態放置html標籤正確。
我使用此代碼將html標籤附加到主體
問題是什麼?
Its我的目標html標籤jquery不能在加載的html上工作

function DisplayLoginPanel() { 
     $('Body').load('Resources/HTMLContents/Login.htm'); 
     LoadNewScript("Resources/OtherTools/js/slide.js"); 
    } 
    function LoadNewScript(ScriptPath) { 
     $.getScript(ScriptPath, function() { 
      alert("Script loaded and executed."); 

     }); 
    } 

回答

4

如果我明白你的問題正確,那麼你需要添加LoadNewScript()功能的complete事件中的​​功能。就像這樣:

function DisplayLoginPanel() { 
$('Body').load('Resources/HTMLContents/Login.htm', function() { 
    LoadNewScript("Resources/OtherTools/js/slide.js"); 
}); 
} 

這樣做的原因是,當你啓動load()你的JavaScript不斷向前發展。它不會等待login.html被加載,因此在添加html之前調用LoadNewScript

查看documentation瞭解更多詳情。

+0

哇..你是對的謝謝你。你能解釋一下嗎? – Shahin 2011-06-05 16:53:41

+1

@shaahin更新了我的答案與它的原因 – Niklas 2011-06-05 17:01:08