<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&dt=1225035130296&lmt=1219829507&prev_slotnames=1891601125&output=html&slotname=3685991503&correlator=1225035130265&url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F08%2F1416.html&ea=0&ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__71.html&frm=0&ga_vid=829866576.1224664711&ga_sid=1225034957&ga_hid=526018334&ga_fc=true&flash=9.0.124.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency></iframe>
javascript包含javascript文件先给出直接封装好的两个js functioninclude_js(path)
{
varsobj=document.createElement('script');
sobj.type="text/javascript";
sobj.src=path;
varheadobj=document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
functioninclude_css(path)
{
varfileref=document.createElement("link")
fileref.rel="stylesheet";
fileref.type="text/css";
fileref.href=path;
}
include_css("css/kefu.css");
include_js("HashMap.js");
include_js("WebComm.js");
-----------------------------
document.write("<scr"+"iptlanguage=javascriptsrc='zdz.js'></scr"+"ipt>");
这样就可以了!中国站长的统计里面就有这个代码!
document.write("<linkhref=\"css/WebComm.css\"rel=\"stylesheet\"type=\"text/css\"/>");
用document.write方法无法放到头文件那里,有时候会有加载先后顺序的问题。用include可以。
第二种方法是用字符串的形式
file1.js:
varfile2='<scriptlanguage="javascript"src="file2.js"><\/script>';
document.write(file2);
第三种方法使用include
//直接包含js文件。
functioninclude_abc(path)
{
varsobj=document.createElement('script');
sobj.type="text/javascript";
sobj.src=path;
varheadobj=document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}
//根据已经包含的第一个js文件路径,包含新的js文件
functioninclude(path)
{
varscripts=document.getElementsByTagName("script");
if(!scripts)return;
varjsPath=scripts[0].src;
jsPath=jsPath.substring(0,jsPath.lastIndexOf('/')+1);
varsobj=document.createElement('script');
sobj.type="text/javascript";
sobj.src=jsPath+path;
varheadobj=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文件路径。