2012-07-12 2 views
1

다른 .js 파일에서 .js 파일을 가져 오는 방법을 알고 싶습니다. CSS다른 jss 파일 안에 jss 파일을 가져 오는 방법. 다른 css 파일 안에 css 파일을 가져 오는 방법과 동일합니다.

all.css 파일은 다음과 같이 간다 파일 ..... 파일 내 custom.js에서 수입 JS/JQuery와-1.7.1.min.js 싶어

 @import "simple1.css"; 
    @import "simple2.css"; 
    @import "simple3.css"; 
    @import "simple4.css"; 

같은 방법으로

custom.js 파일이 다음과 같이 변경됩니다.

$(document).ready(function(){ 

    $("#AddImage").html("<img src='"+clientID+".jpg'/>"); 

    }); 

나는 내 custom.js 파일에 포함 할 JS/JQuery와-1.7.1.min.js

 <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> 

같이 포함하지 않는다.

도와주세요! 미리 감사드립니다 !!!

+0

http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file –

+0

아니요. 나에게 맞지 않습니다 .... 몇 가지 간단한 코드가 있습니다. – Christina

답변

2

사용하여 나를 위해 일한 사용할 수 있습니다.

function importJs(url) 
{ 
    var head = document.getElementsByTagName('head')[0]; 
    var script = document.createElement('script'); 
    script.type = 'text/javascript'; 
    script.src = url; 

    head.appendChild(script); 
} 

지금 당신이 어떤 JS에서 importJs()을 사용할 수 있습니다

importJs("myScript.js"); 

아래의 예를 참조 코드를 실행합니다. CSS에서 @import과 비슷한 JS에 사용할 수 있습니다.

1

이 플러그인은 http://code.google.com/p/jquery-include/입니다. 이 jQuery 플러그인은 SSI와 유사한 브라우저 기반 파일 포함 기능을 제공합니다. 그리고

$(document).includeReady(function() { 

     // initialisation code here 
     // e.g. modify include dom 

}); 

<span data-src="includes/test1.html"> 

     <p class="error-msg">include has not loaded</p> 

</span> 
2

이 코드 당신은 다음과 같은 기능을 만들 수 있습니다 jQuery를

$.getScript("myscript.js"); 
관련 문제