我有一个 main.js 外部文件,我在其中实现:
function initialize() {
...
}
和我调用的 main.php 文件:
<script type="text/javascript" src="./main.js"></script>
然后我打电话:
$(window).load(function() {
initialize();
}
我知道 window.load 会在所有内容都加载并准备就绪后触发代码。
为什么会返回ReferenceError: initialize is not defined
?
编辑:这是我的样本形式的代码:
// # main.js.php file
<?php
session_start();
include_once("include/functions.php");
session_write_close();
?>
var elements = [];
var element = {
container: "",
visible: false,
init : function(div) {
....
}
};
function initialize() {
elements.push(element.initialize("mydiv"));
}
// # main.php file
<?php
session_start();
include_once("include/functions.php");
include_once("include/db_engine.php");
session_write_close();
}
?>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html" />
<link rel="stylesheet" type="text/css" href="./css/stile.css" media="all" />
<script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="./main.js.php"></script>
<script type="text/javascript">
$(window).load(function() {
initialize();
});
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>