日期:2014-05-16  浏览次数:20284 次

关于js的namespace定义和函数调用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var GLOBAL={};
</script>
<script type="text/javascript">
(function () {
    GLOBAL.A = {}
    GLOBAL.A.na2 = "222222222";
    GLOBAL.A.na1 = {};
    GLOBAL.A.na1.name = "mimiiii"
    GLOBAL.A.na1.action = function () {
        alert(GLOBAL.A.na1.name);
        alert(GLOBAL.A.na2);
        alert("mysdsd");
    }
})()
$(function () {
    GLOBAL.A.na1.action();
})
/*
(function () {
    function $(id) {
        return document.getElementById(id);
    }
    function _setStyle() {
        $("test").style["color"] = "#f00";
    }
    window.mySpace = {};
    window.mySpace.setStyle = _setStyle;
})();
$(function () {
    window.mySpace.setStyle();
})
*/
</script>
</head>
<body>
<div id="test">asdasdasdasdasdasdasd</div>
<div class="as">
  <input type="button" value="按钮1" id="btn1" onclick="GLOBAL.A.na1.action()" />
</div>
</body>
</html>