我試圖獲取TestService.Server.WWW_SERVER_URL,但TestService.Server未定義。 當我打電話給test1()時,它運行良好。但我無法訪問對象文字測試服務器。 有其他方法嗎?在另一個JavaScript文件中使用javascript文件中聲明的全局變量
的test.html
<script type="text/javascript" language="javascript" src="TestService.js"></script>
<script type="text/javascript" language="javascript">
function test() {
alert("TestService.Server.WWW_SERVER_URL[" + TestService.Server.WWW_SERVER_URL + "]");
//test1();
}
</script>
TestService.js
document.write("<scr" + "ipt type='text/javascript' src='TestServer.js'><" + "/scr" + "ipt>");
var TestService = {
Server: TestServer,
Delimiter: ""
};
function test1() {
test2();
}
TestServer.js
var TestServer = {
WWW_SERVER_URL: "http://www.test.com"
};
function test2() {
alert("test2 has been called!");
}