2007-01-29 08:11
插入js:

var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://www.somedomain.com/somescript.js';
headID.appendChild(newScript);

同理插入css:

var headID = document.getElementsByTagName("head")[0];         
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'FireFox.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);
hehechuan 发表于 技术文档 | 标签:javascript css  | 评论(0) | 引用(0)
2007-01-14 00:36
这里发一些javascript的小特效,你可以放在你的公告模块中,当然以下的javascript大多支持IE,但不一定在firefox下可以正常显示。

1,显示距离xx天xx月xx日还有多少天。。。
输入内容:
<SCRIPT language=javascript><!--
BirthDay=new Date("2007/10/21");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
//-->
</SCRIPT><SCRIPT language=javascript><!--
document.write("到我的生日还有"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒了!");
//-->
</SCRIPT>

将第二行的2007/10/21按照年/月/日的格式改成你要的日期,然后把下面的文字修改一下就好了。
hehechuan 发表于 Blog开发 | 标签:blogease javascript  | 评论(3) | 引用(0)
2007-01-03 00:29
最近一个项目中,需要做这样一件事情:
浏览器窗口中高和宽需要安百分比显示一个界面,当用户改变窗口大小时,界面也会随着进行变化,也就是说,不会出现任何的滚动条。

横向的html只需要使用百分比就可以搞定了,主要是纵向,因为浏览器纵向是可以无限长的,所以需要通过javascript来获取屏幕当前空白工作区域的高度,然后设置界面的高度。我的方法如下:

<html>
<head>
<script>
function init()
{
     var windowWidth, windowHeight;
     if (self.innerHeight) {  // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
     } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
     } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
     } 
   

    var firstsheet=document.styleSheets[0];
    var therules=firstsheet.cssRules? firstsheet.cssRules: firstsheet.rules;
    var treeHeight =  windowHeight - 238;
    therules[0].style.height= treeHeight + "px";
}
</script>
</head>
<body onresize="init();">
<script language="javascript" type="text/javascript">
init();
</script>
</body>

当载入页面或onresize事件被激发后,执行 init ,取得屏幕高度参数,然后重新设定css高度。

这个代码在ie/firefox都可以正常的执行。
hehechuan 发表于 技术文档 | 标签:javascript  | 评论(1) | 引用(0)