//直接包含js文件。
function include_abc(path)
{
var sobj = document.createElement('script');
sobj.type = "text/javascript";
sobj.src = path;
var headobj = document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
//根据已经包含的第一个js文件路径,包含新的js文件
function include(path)
{
var scripts = document.getElementsByTagName("script");
if(!scripts) return;
var jsPath = scripts[0].src;
jsPath=jsPath.substring(0,jsPath.lastIndexOf('/')+1);
var sobj = document.createElement('script');
sobj.type = "text/javascript";
sobj.src = jsPath+path;
var headobj = document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
例如:
现在已经有一Common.js文件包含在aspx页面上,路径是src="/JScript/Common.js"
如果用include包含: include("WebsiteConfig.js");将把WebsiteConfig.js包含进页面,路径和Common.js相同。
如果用include_abc包含则需要全路径,include_abc("/JScript/WebsiteConfig.js");
使用include,必须要求页面上已经有一个包含的js文件.
使用include_abc则不需要任何条见,就可以包含,但是必须指定要包含的js文件路径。
http://www.codediy.net/bbs/viewthread.php?tid=225
function include_abc(path)
{
var sobj = document.createElement('script');
sobj.type = "text/javascript";
sobj.src = path;
var headobj = document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
//根据已经包含的第一个js文件路径,包含新的js文件
function include(path)
{
var scripts = document.getElementsByTagName("script");
if(!scripts) return;
var jsPath = scripts[0].src;
jsPath=jsPath.substring(0,jsPath.lastIndexOf('/')+1);
var sobj = document.createElement('script');
sobj.type = "text/javascript";
sobj.src = jsPath+path;
var headobj = document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
例如:
现在已经有一Common.js文件包含在aspx页面上,路径是src="/JScript/Common.js"
如果用include包含: include("WebsiteConfig.js");将把WebsiteConfig.js包含进页面,路径和Common.js相同。
如果用include_abc包含则需要全路径,include_abc("/JScript/WebsiteConfig.js");
使用include,必须要求页面上已经有一个包含的js文件.
使用include_abc则不需要任何条见,就可以包含,但是必须指定要包含的js文件路径。
http://www.codediy.net/bbs/viewthread.php?tid=225