1、判断网页是否过期 getTime()
用于实现广告过期。
<head>
<h1>判断网页是否过期</h1>
<hr>
<script>
<!--
today = new Date() //取得现在的时间
TheDay = new Date(2005,12,31) //取得结束的时间 2006/1/4 00:00:00
//如果 today.getTime() > TheDay.getTime()
if (today.getTime()>TheDay.getTime())
{
document.write('<h1>抱歉,你访问的网页已经过期!</h1>') }
else
{
document.write('<font size=5>你的网页尚未过期.</font>')
}
//-->
</script>
2、在线时钟实例 setTimeout()函数
setTimeout()函数
TimerID = setTimeout('showtime',1000)
通过setTimeout 来刷新时间 间隔1000=1秒
<head>
<script>
<!--
function showtime()
{
document.CLOCK.ALARM.value = new Date().toString()
TimerID = setTimeout("showtime()",1000)
}
//-->
</script>
</head>
<body onLoad="showtime()">
<Form name="CLOCK">
<input name="ALARM" type="text" size="45" value="">
如无效果请刷新
</form>
</body>
3、status window自带函数状态栏提示
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
<!--
window.defaultStatus="这里是主页"
//-->
</script>
</head>
<body>
<a href="abc.htm" οnmοuseοver='window.status="abc.htm";return true'>abc</a><br>
<a href="def.htm" οnmοuseοver='window.status="def.htm";return true'>def</a>
</body>
</html>
4、setTimeout 函数,自动链向新网站
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function Redir()
{
a ="http://homepage.yesky.com" //在此输入新网站的网址
TimerID=setTimeout('window.location.href=a',2000)
}
//-->
</script>
</head>
<body οnlοad="Redir()">
我们的网站搬新家了!请单击下面的超链接进入我们的新网站<br>
<a href="http://www.chinaz.com">中国站长站</a>
<br> 2秒后自动进入新的网站,请耐心等待。
</body>
</html>
5、广告字幕实例
设置0.3秒后再次调用MARQUEE()函数
TimerID = setTimeout("marquee()",300)
广告字幕触发事件
<body οnlοad="marquee()">
<head>
<script>
<!--
var ShowString =" "
+"Space,The final frontier... These are the"
+"voyages of the Starship Enterprise, its"
+"continuing mission: to explore strange"
+"new worlds, to seek out new life and new"
+"civilizatins, to boldly go where no man"
+"has gone before.______________________________"
+"宇宙,人类的最终边界....太空船企业号的旅程,"
+"是为了探索陌生新世界,找寻新生命与新文明,勇"
+"驶向人类足迹从未的领域."
//--------------------------------
var ShowWidth = 50
var ShowHead = 0
var ShowTail = ShowWidth
var ShowLength= ShowString.length
//--------------------------------
function marquee()
{
var DisplayString
if (ShowHead<ShowTail)
DisplayString = ShowString.substring(ShowHead,ShowTail)
else
DisplayString = ShowString.substring(ShowHead,ShowLength)
+ShowString.substring( 0,ShowTail)
//--------------------------------
ShowHead = (ShowHead + 2) % ShowLength
ShowTail = (ShowTail + 2) % ShowLength
//--------------------------------
document.RUNNING.SHOWPAD.value = DisplayString
//--------------------------------
TimerID = setTimeout("marquee()",300)
}
//->
</script>
</head>
<body οnlοad="marquee()">
<center>
<form name="RUNNING">
<INPUT NAME="SHOWPAD" size=40 Type="text" value="">
如无效果请刷新。
</form>
</center>
</body>
6 更新记录后关闭子窗口并刷新父窗口的Javascript
有时我们需要在新打开的窗口里面编辑信息,等编辑完了,需要将当前窗口关闭并且刷新父窗口,以使修改生效,本文就是介绍用 javascript 来实现"更新记录后关闭子窗口并刷新父窗口".
父窗口代码:
HTML:
子窗口代码:
HTML:
用于实现广告过期。
<head>
<h1>判断网页是否过期</h1>
<hr>
<script>
<!--
today = new Date() //取得现在的时间
TheDay = new Date(2005,12,31) //取得结束的时间 2006/1/4 00:00:00
//如果 today.getTime() > TheDay.getTime()
if (today.getTime()>TheDay.getTime())
{
document.write('<h1>抱歉,你访问的网页已经过期!</h1>') }
else
{
document.write('<font size=5>你的网页尚未过期.</font>')
}
//-->
</script>
2、在线时钟实例 setTimeout()函数
setTimeout()函数
TimerID = setTimeout('showtime',1000)
通过setTimeout 来刷新时间 间隔1000=1秒
<head>
<script>
<!--
function showtime()
{
document.CLOCK.ALARM.value = new Date().toString()
TimerID = setTimeout("showtime()",1000)
}
//-->
</script>
</head>
<body onLoad="showtime()">
<Form name="CLOCK">
<input name="ALARM" type="text" size="45" value="">
如无效果请刷新
</form>
</body>
3、status window自带函数状态栏提示
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
<!--
window.defaultStatus="这里是主页"
//-->
</script>
</head>
<body>
<a href="abc.htm" οnmοuseοver='window.status="abc.htm";return true'>abc</a><br>
<a href="def.htm" οnmοuseοver='window.status="def.htm";return true'>def</a>
</body>
</html>
4、setTimeout 函数,自动链向新网站
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function Redir()
{
a ="http://homepage.yesky.com" //在此输入新网站的网址
TimerID=setTimeout('window.location.href=a',2000)
}
//-->
</script>
</head>
<body οnlοad="Redir()">
我们的网站搬新家了!请单击下面的超链接进入我们的新网站<br>
<a href="http://www.chinaz.com">中国站长站</a>
<br> 2秒后自动进入新的网站,请耐心等待。
</body>
</html>
5、广告字幕实例
设置0.3秒后再次调用MARQUEE()函数
TimerID = setTimeout("marquee()",300)
广告字幕触发事件
<body οnlοad="marquee()">
<head>
<script>
<!--
var ShowString =" "
+"Space,The final frontier... These are the"
+"voyages of the Starship Enterprise, its"
+"continuing mission: to explore strange"
+"new worlds, to seek out new life and new"
+"civilizatins, to boldly go where no man"
+"has gone before.______________________________"
+"宇宙,人类的最终边界....太空船企业号的旅程,"
+"是为了探索陌生新世界,找寻新生命与新文明,勇"
+"驶向人类足迹从未的领域."
//--------------------------------
var ShowWidth = 50
var ShowHead = 0
var ShowTail = ShowWidth
var ShowLength= ShowString.length
//--------------------------------
function marquee()
{
var DisplayString
if (ShowHead<ShowTail)
DisplayString = ShowString.substring(ShowHead,ShowTail)
else
DisplayString = ShowString.substring(ShowHead,ShowLength)
+ShowString.substring( 0,ShowTail)
//--------------------------------
ShowHead = (ShowHead + 2) % ShowLength
ShowTail = (ShowTail + 2) % ShowLength
//--------------------------------
document.RUNNING.SHOWPAD.value = DisplayString
//--------------------------------
TimerID = setTimeout("marquee()",300)
}
//->
</script>
</head>
<body οnlοad="marquee()">
<center>
<form name="RUNNING">
<INPUT NAME="SHOWPAD" size=40 Type="text" value="">
如无效果请刷新。
</form>
</center>
</body>
6 更新记录后关闭子窗口并刷新父窗口的Javascript
有时我们需要在新打开的窗口里面编辑信息,等编辑完了,需要将当前窗口关闭并且刷新父窗口,以使修改生效,本文就是介绍用 javascript 来实现"更新记录后关闭子窗口并刷新父窗口".
父窗口代码:
HTML:
<a href="javascript:void(0)" onclick="window.open('child.html','child','width=400,height=300,left=200,top=200');">打开子窗口</a>
子窗口代码:
HTML:
<script language="JavaScript" type="text/javascript"> <!-- function refreshParent() { window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) { window.opener.progressWindow.close(); } window.close(); } //--> </script> <a href="javascript:void(0)" onclick="refreshParent()">刷新父窗口并关闭当前窗口</a>
十个jquery的例子
http://www.chinaret.com/user/topic_view.aspx?u=blogcat&id=6d22f981-6fe8-4378-9542-fd94af2ec424