时间:2021-07-01 10:21:17 帮助过:3人阅读
(function(){
if(!window.myNamespace){window['myNameSpace']={};}
function $(id){
return document.getElementById(id);
}
function alertNodeName(id){
alert($(id).nodeName);
}
window['myNameSpace']['showNodeName'] = alertNodeName;
})();
这样我们就打造了一个自己的命名空间。
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
(function(){
function $(id){
return document.getElementById(id);
}
function alertNodeName(id){
alert($(id).nodeName);
}
window['myNameSpace'] = {};
window['myNameSpace']['showNodeName'] = alertNodeName;
})();
function Test(){
myNameSpace.showNodeName("T");
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="Test()">
<INPUT TYPE="text" NAME="T" ID="T" VALUE="Test">
</BODY>
</HTML>