2017-07-09 102 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(); 
    }); 
}); 

现在,你只需要调用已经存在的功能加载新的内容后