变量、函数不冲突仅仅是前提,具体方法有这么几个:1、手工添加Script元素以及脚本到网页里,一般情况下我建议你添加在</body>后面。2、手工添加Script元素以SRC属性引用外部脚本文件。3、动态添加,用脚本创建一个Script元素,然后添加到网页里。有个我们自己设计的一个办法,我们自己叫做BootScript法。 在所有网页里都引用一个AriesScript_mBtl_CodeLib.vbs,这个文件包含有动态添加脚本和样式的函数。我们制作网页是用“模板法”,根据网页的内容总结出几个“模板”,只要把模板添上内容就是一个网页。比如说你要做一个长篇文本网页,则我们用Type_TextEx模板,这个模板里除了AriesScript_mBtl_CodeLib外还加载一个AriesScript_mBot_TextEx.vbs,这个脚本文件里动态加载所有针对长篇文本网页而做的通用的脚本。如果特殊对于某个单独的网页有要求,则使用单独的AriesScript_mBot_网页简写名称.vbs加载单独对策的脚本。下面是我们的AriesScript_mBtl_CodeLib部分代码,虽然是VBScript的,但是使用的方法和JS一样,稍微修改一下JS一样可以实现:'所属:AriesScript 1.0
'模块:Mahayana Boot Lib CodeLib
'说明:加载'[声明部]
Dim mBtl_CodeLib_SystemScriptVerName '脚本版本前缀
Dim mBtl_CodeLib_SystemScriptInfo '系统加载脚本的信息公共变量。
Dim mBtl_CodeLib_SystemScriptLanguage '系统默认脚本语言。
Dim mBtl_CodeLib_SystemScriptInfos() '系统脚本信息数组ReDim mBtl_CodeLib_SystemScriptInfos(0)'[初始化]
mBtl_CodeLib_SystemScriptLanguage="VBScript"
mBtl_CodeLib_SystemScriptVerName="Aries"'[注册部]
mBtl_CodeLib_SystemScriptInfo_AddItem "Mahayana Boot Lib CodeLib","AriesScript_mBtl_CodeLib.vba"'[加载部]
mBtl_CodeLib_ScriptLoad "AriesScript_mBot_System.vba",window'[脚本信息服务函数]
Function mBtl_CodeLib_SystemScriptInfo_AddItem(pScriptName,pScriptFileName)
'功能:添加脚本信息到mBtl_CodeLib_SystemScriptInfo变量。
'参数:pScriptName 脚本名
' pScriptFileName 脚本文件名 tOutStr=mBtl_CodeLib_SystemScriptInfo
tOutStr=tOutStr & Chr(13) & Chr(10) & mBtl_CodeLib_SystemScriptVerName & " " & pScriptName & " " & "[" & pScriptFileName & "]"
tArrayEnd=UBound(mBtl_CodeLib_SystemScriptInfos)
ReDim Preserve mBtl_CodeLib_SystemScriptInfos(tArrayEnd)
mBtl_CodeLib_SystemScriptInfos(tArrayEnd)=pScriptFileName mBtl_CodeLib_SystemScriptInfo=tOutStr
End Function'[脚本导入函数]
Function mBtl_CodeLib_ScriptLoad(pURL,pWindow)
'功能:导入指定脚本到指定窗口对象。
'参数:pURL 指定Script文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个VBScript的script要素。该要素指定src属性为pURL。
'参数:pURL 指定Script文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("script")
With tOutObj
.language=mBtl_CodeLib_SystemScriptLanguage
.type="text/" & mBtl_CodeLib_SystemScriptLanguage
.src=pURL
End With
Set mBtl_CodeLib_ScriptObjCreateByURL=tOutObj
End Function'[样式导入函数]
Function mBtl_CodeLib_StyleLoad(pURL,pWindow)
'功能:导入指定样式到指定窗口对象。
'参数:pURL 指定css文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个Style的Link要素。该要素指定href属性为pURL。
'参数:pURL 指定css文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("link")
With tOutObj
.rel="StyleSheet"
.type="text/css"
.href=pURL
End With
Set mBtl_CodeLib_StyleObjCreateByURL=tOutObj
End Function
'模块:Mahayana Boot Lib CodeLib
'说明:加载'[声明部]
Dim mBtl_CodeLib_SystemScriptVerName '脚本版本前缀
Dim mBtl_CodeLib_SystemScriptInfo '系统加载脚本的信息公共变量。
Dim mBtl_CodeLib_SystemScriptLanguage '系统默认脚本语言。
Dim mBtl_CodeLib_SystemScriptInfos() '系统脚本信息数组ReDim mBtl_CodeLib_SystemScriptInfos(0)'[初始化]
mBtl_CodeLib_SystemScriptLanguage="VBScript"
mBtl_CodeLib_SystemScriptVerName="Aries"'[注册部]
mBtl_CodeLib_SystemScriptInfo_AddItem "Mahayana Boot Lib CodeLib","AriesScript_mBtl_CodeLib.vba"'[加载部]
mBtl_CodeLib_ScriptLoad "AriesScript_mBot_System.vba",window'[脚本信息服务函数]
Function mBtl_CodeLib_SystemScriptInfo_AddItem(pScriptName,pScriptFileName)
'功能:添加脚本信息到mBtl_CodeLib_SystemScriptInfo变量。
'参数:pScriptName 脚本名
' pScriptFileName 脚本文件名 tOutStr=mBtl_CodeLib_SystemScriptInfo
tOutStr=tOutStr & Chr(13) & Chr(10) & mBtl_CodeLib_SystemScriptVerName & " " & pScriptName & " " & "[" & pScriptFileName & "]"
tArrayEnd=UBound(mBtl_CodeLib_SystemScriptInfos)
ReDim Preserve mBtl_CodeLib_SystemScriptInfos(tArrayEnd)
mBtl_CodeLib_SystemScriptInfos(tArrayEnd)=pScriptFileName mBtl_CodeLib_SystemScriptInfo=tOutStr
End Function'[脚本导入函数]
Function mBtl_CodeLib_ScriptLoad(pURL,pWindow)
'功能:导入指定脚本到指定窗口对象。
'参数:pURL 指定Script文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个VBScript的script要素。该要素指定src属性为pURL。
'参数:pURL 指定Script文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("script")
With tOutObj
.language=mBtl_CodeLib_SystemScriptLanguage
.type="text/" & mBtl_CodeLib_SystemScriptLanguage
.src=pURL
End With
Set mBtl_CodeLib_ScriptObjCreateByURL=tOutObj
End Function'[样式导入函数]
Function mBtl_CodeLib_StyleLoad(pURL,pWindow)
'功能:导入指定样式到指定窗口对象。
'参数:pURL 指定css文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个Style的Link要素。该要素指定href属性为pURL。
'参数:pURL 指定css文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("link")
With tOutObj
.rel="StyleSheet"
.type="text/css"
.href=pURL
End With
Set mBtl_CodeLib_StyleObjCreateByURL=tOutObj
End Function
'模块:Mahayana Boot Lib CodeLib
'说明:加载'[声明部]
Dim mBtl_CodeLib_SystemScriptVerName '脚本版本前缀
Dim mBtl_CodeLib_SystemScriptInfo '系统加载脚本的信息公共变量。
Dim mBtl_CodeLib_SystemScriptLanguage '系统默认脚本语言。
Dim mBtl_CodeLib_SystemScriptInfos() '系统脚本信息数组ReDim mBtl_CodeLib_SystemScriptInfos(0)'[初始化]
mBtl_CodeLib_SystemScriptLanguage="VBScript"
mBtl_CodeLib_SystemScriptVerName="Aries"'[注册部]
mBtl_CodeLib_SystemScriptInfo_AddItem "Mahayana Boot Lib CodeLib","AriesScript_mBtl_CodeLib.vba"'[加载部]
mBtl_CodeLib_ScriptLoad "AriesScript_mBot_System.vba",window'[脚本信息服务函数]
Function mBtl_CodeLib_SystemScriptInfo_AddItem(pScriptName,pScriptFileName)
'功能:添加脚本信息到mBtl_CodeLib_SystemScriptInfo变量。
'参数:pScriptName 脚本名
' pScriptFileName 脚本文件名 tOutStr=mBtl_CodeLib_SystemScriptInfo
tOutStr=tOutStr & Chr(13) & Chr(10) & mBtl_CodeLib_SystemScriptVerName & " " & pScriptName & " " & "[" & pScriptFileName & "]"
tArrayEnd=UBound(mBtl_CodeLib_SystemScriptInfos)
ReDim Preserve mBtl_CodeLib_SystemScriptInfos(tArrayEnd)
mBtl_CodeLib_SystemScriptInfos(tArrayEnd)=pScriptFileName mBtl_CodeLib_SystemScriptInfo=tOutStr
End Function'[脚本导入函数]
Function mBtl_CodeLib_ScriptLoad(pURL,pWindow)
'功能:导入指定脚本到指定窗口对象。
'参数:pURL 指定Script文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_ScriptObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个VBScript的script要素。该要素指定src属性为pURL。
'参数:pURL 指定Script文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("script")
With tOutObj
.language=mBtl_CodeLib_SystemScriptLanguage
.type="text/" & mBtl_CodeLib_SystemScriptLanguage
.src=pURL
End With
Set mBtl_CodeLib_ScriptObjCreateByURL=tOutObj
End Function'[样式导入函数]
Function mBtl_CodeLib_StyleLoad(pURL,pWindow)
'功能:导入指定样式到指定窗口对象。
'参数:pURL 指定css文件的地址。
' pWindow 导入该要素的目的窗口对象。
Set tOutObj=mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
pWindow.document.body.insertBefore tOutObj
End FunctionFunction mBtl_CodeLib_StyleObjCreateByURL(pURL,pWindow)
'功能:在指定窗口对象创建一个Style的Link要素。该要素指定href属性为pURL。
'参数:pURL 指定css文件的地址。
' pWindow 创建该要素的目的窗口对象。
Set tOutObj=pWindow.document.createElement("link")
With tOutObj
.rel="StyleSheet"
.type="text/css"
.href=pURL
End With
Set mBtl_CodeLib_StyleObjCreateByURL=tOutObj
End Function