2017-07-09 40 views
0

我的html文檔已經有了scripts.js文件。但我需要在加載外部html文件的情況下重新編寫scripts.js文件中的所有函數。加載外部html文件的重新加載函數

$("#loader").load('projects/project_01.html', function() { 
    $.getScript("js/scripts.js"); 
}); 

它調用的腳本文件,但並不功能再次合作。我如何重新加工scripts.js文件中的每個加載新文件的所有功能?

回答

0

如果scripts.js已經加載,你可能只是需要做一些這樣的文件:

// group content funcionality into function(s) 
function contentInit(){ 
    $('button').doSomething(); 
    $('input').change(doSomethingElse);  
} 

// initial page load 
$(document).ready(function(){ 
    // for initial page content 
    contentInit(); 

    $("#loader").load('projects/project_01.html', function() { 
     // for ajax loaded content 
     contentInit(); 
    }); 
}); 

現在,你只需要調用已經存在的功能加載新的內容後