JS代码:
1.让文字不停地滚动
<MARQUEE>滚动文字</MARQUEE>
2.记录并显示网页的最后修改时间
<script language=javascript>
document.write("最后更新时间: " + document.lastModified + "")
</script>
3.关闭当前窗口
<a href="/"onClick="javascript:window.close();return false;">关闭窗口</a>
4.5秒后关闭当前页
<script language="javascript">
<!--
setTimeout(''window.close();'',5000);
-->
</script>
5.2秒后载入指定网页
<head>
<meta http-equiv="refresh" content="2;URL=http://你的网址">
</head>
6.添加到收藏夹
<Script Language="javascript">
function bookmarkit() {
window.external.addFavorite(''http://你的网址'',''你的网站名称'')
}
if (document.all)document.write(''<a href="#" onClick="bookmarkit()">加入收藏夹</a>'')
</Script>
7.让超链接不显示下划线
<style type="text/css">
<!-
a:link{text-decoration:none}
a:hover{text-decoration:none}
a:visited{text-decoration:none}
->
</style>
8.禁止鼠标右键的动作
<Script Language = "javascript">
function click() {
if (event.button==2||event.button==3)
{
alert(''禁止鼠标右键'');
}
document.onmousedown=click
// -->
</Script>
9.设置该页为首页
<body bgcolor="#FFFFFF" text="#000000">
<!-- 网址:http://你的网址-->
<a class="chlnk" style="cursor:hand" HREF onClick="this.style.behavior=''url(#default#homepage)''; this.setHomePage(''你的网站名称);"><font color="000000" size="2" face="宋体">设为首页</font></a>
</body>
10.节日倒计时
<Script Language="javascript">
var timedate= new Date("December 25,2003");
var times="圣诞节";
var now = new Date();
var date = timedate.getTime() - now.getTime();
var time = Math.floor(date / (1000 * 60 * 60 * 24));
if (time >= 0)
document.write("现在离"+times+"还有: "+time +"天");
</Script>
11.单击按钮打印出当前页
<Script Language="javascript">
<!-- Begin
if (window.print) {
document.write(''<form>'' + ''<input type=button name=print value="打印本页" '' + ''onClick="javascript:window.print()"></form>'');
}
// End -->
</Script>
12.单击按钮‘另存为’当前页
<input type="button" name="Button" value="保存本页" onClick="document.all.button.ExecWB(4,1)">
<object id="button" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
<embed width="0" height="0"></embed>
</object>
13.显示系统当前日期
<script language=javascript>
today=new Date();
function date(){
this.length=date.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=date.arguments
}
var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
document.write( "<font color=##000000 style=''font-size:9pt;font-family: 宋体''> ", today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",d[today.getDay()+1],"</font>" );
</script>
14.不同时间段显示不同问候语
<Script Language="javascript">
<!--
var text="";
day = new Date( );
time = day.getHours( );
if (( time>=0) && (time < 7 ))
text="夜猫子,要注意身体哦! "
if (( time >= 7 ) && (time < 12))
text="今天天气……哈哈哈,不去玩吗?"
if (( time >= 12) && (time < 14))
text="午休时间哦,朋友一定是不习惯午睡的吧?!"
if (( time >=14) && (time < 18))
text="下午茶的时间到了,休息一下吧! "
if ((time >= 18) && (time <= 22))
text="您又来了,可别和MM聊太久哦!"
if ((time >= 22) && (time < 24))
text="很晚了哦,注意休息呀!"
document.write(text)
//--->
</Script>
15.水中倒影效果
<img id="reflect" src="你自己的图片文件名" width="175" height="59">
<script language="javascript">
function f1(){
setInterval("mdiv.filters.wave.phase+=10",100);
}
if (document.all) {
document.write(''<img id=mdiv src="''+document.all.reflect.src+''" style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30) blur() flipv()">'')
window.onload=f1
}
</script>
16.慢慢变大的窗口
<Script Language="javascript">
<!--
var Windowsheight=100
var Windowswidth=100
var numx=5
function openwindow(thelocation){
temploc=thelocation
if(!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById)){
window.open(thelocation)
return
}
windowsize=window.open("","","scrollbars")
windowsize.moveTo(0,0)
windowsize.resizeTo(100,100)
tenumxt()
}
function tenumxt(){
if (Windowsheight>=screen.availHeight-3)
numx=0
windowsize.resizeBy(5,numx)
Windowsheight+=5
Windowswidth+=5
if (Windowswidth>=screen.width-5){
windowsize.location=temploc
Windowsheight=100
Windowswidth=100
numx=5
return
}
setTimeout("tenumxt()",50)
}
//-->
</script>
<p><a href="javascript:openwindow(http://www.xxx.com)">进入</a>
17.改变IE地址栏的IE图标
我们要先做一个16*16的icon(图标文件),保存为index.ico。把这个图标文件上传到根目录下并在首页<head></head>之间加上如下代码:
<link REL = "Shortcut Icon" href="index.ico">
html 另存为/打印/刷新/查看原文件等 代码
■打开■
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■另存为■
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■属性■
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■打印■
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■页面设置■
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■刷新■
<input type=button value=刷新 name=refresh onclick="window.location.reload()">
■导入收藏■
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);>
■导出收藏■
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);>
■加入收藏■
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹>
■整理收藏夹■
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹>
■查看原文件■
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件>
■语言设置■
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置>
■前进■
<INPUT name=Submit onclick=history.go(1) type=submit value=前进>
■后退■
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>
<html>
<title>页面提交时出现等待窗口示例</title>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
//By Dicky 2005-2-17 11:16:49
function Window_Load(Flag)
{
if (Flag == 0)
{
document.all[Loading].style.display = block;
//show the window
}
else
{
document.all[Loading].style.display = none;
//hide the window
}
}
//-->
</SCRIPT>
</head>
<body leftMargin=0 topMargin=50 onload="Window_Load(1);">
<div id="Loading" style="position:absolute;z-index:3;top:200px;left:250px;width:250;height:60;border-width:1;border-style:ridge;background-color:green;padding-top:10px"><center><table border="0"><tr><td valign="middle"><img src="cursor.gif" border="0" WIDTH="30" HEIGHT="30"></td><td> </td><td valign="middle"><span id=txtLoading0 style="font-size:14px;">正在初始化页面,请稍候...</span><br><span id=txtLoading1 style="font-size:14px;">Loading,please wait...</span></td></tr></table></center></div>
<form name="form1" method="post" action="" onSubmit="Window_Load(0);">
<center>页面提交时出现等待窗口示例<input name=submit type=submit value=提交>
</center>
</form>
</body>
</html>
1.overflow内容溢出时的设置(设定被设定对象是否显示滚动条)
overflow-x水平方向内容溢出时的设置
overflow-y垂直方向内容溢出时的设置
以上三个属性设置的值为visible(默认值)、scroll、hidden、auto。
2.scrollbar-3d-light-color立体滚动条亮边的颜色(设置滚动条的颜色)
scrollbar-arrow-color上下按钮上三角箭头的颜色
scrollbar-base-color滚动条的基本颜色
scrollbar-dark-shadow-color立体滚动条强阴影的颜色
scrollbar-face-color立体滚动条凸出部分的颜色
scrollbar-highlight-color滚动条空白部分的颜色
scrollbar-shadow-color立体滚动条阴影的颜色
我们通过几个实例来讲解上述的样式属性:
1.让浏览器窗口永远都不出现滚动条
没有水平滚动条
<body style="overflow-x:hidden">
没有垂直滚动条
<body style="overflow-y:hidden">
没有滚动条
<body style="overflow-x:hidden;overflow-y:hidden">或<body
style="overflow:hidden">
2.设定多行文本框的滚动条
没有水平滚动条
<textarea style="overflow-x:hidden"></textarea>
没有垂直滚动条
<textarea style="overflow-y:hidden"></textarea>
没有滚动条
<textarea style="overflow-x:hidden;overflow-y:hidden"></textarea>
或<textarea style="overflow:hidden"></textarea>
3.设定窗口滚动条的颜色
设置窗口滚动条的颜色为红色<body style="scrollbar-base-color:red">
scrollbar-base-color设定的是基本色,一般情况下只需要设置这一个属性就可以达到改变滚动条颜色的目的。
加上一点特别的效果:
<body style="scrollbar-arrow-color:yellow;scrollbar-base-color:lightsalmon">
4.在样式表文件中定义好一个类,调用样式表。
<style>
.coolscrollbar{scrollbar-arrow-color:yellow;scrollbar-base-color:lightsalmon;}
</style>
这样调用:
<textarea class="coolscrollbar"></textarea>
WEB打印
<html>
<head>
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
<tr>
<td width="29%" class="tdp"> </td>
<td width="28%" class="tdp"> </td>
<td width="43%" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧</td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
背景音乐刷新自动更换
<SCRIPT LANGUAGE="javascript">
<!--
var sound1="http://歌曲地址"
var sound2="http://歌曲地址"
var sound3="http://歌曲地址"
var sound4="http://歌曲地址"
var sound5="http://歌曲地址"
var sound6="http://歌曲地址"
var sound7="http://歌曲地址"
var sound8="http://歌曲地址"
var sound9="http://歌曲地址"
var sound10="http://歌曲地址"
var x=Math.round(Math.random()*10)
if (x==0) x=sound1
else if (x==1) x=sound2
else if (x==2) x=sound3
else if (x==3) x=sound4
else if (x==4) x=sound5
else if (x==5) x=sound6
else if (x==6) x=sound7
else if (x==7) x=sound8
else if (x==8) x=sound9
else x=sound10
if (navigator.appName=="Microsoft Internet Explorer"
document.write(<bgsound src=http://dev.csdn.net/article/+"+x+"+ loop="infinite">)
else
document.write(<embed src=http://dev.csdn.net/article/+"+x+"+hidden="true" autostart="true" loop="true">)
//-->
</SCRIPT>
随机广告代码
<SCRIPT LANGUAGE="JavaScript"><!-- BANNER ROTATOR
var how_many_ads = 3
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
//**************************** AD NUMBER ONE ****************
if (ad==1){
url="http://www.youradvertiser.com";
alt="Advertiser NumberOne";
banner="http://www.yourdomain.com/images/banner1.gif";
width="468";
height="60";
}
//**************************** AD NUMBER TWO ****************
if (ad==2) {
url="http://www.youradvertiser.com";
alt="Advertiser Number Two";
banner="http://www.yourdomain.com/images/banner2.gif";
width="468";
height="60";
}
//**************************** AD NUMBER ONE ****************
if (ad==3) {
url="http://www.youradvertiser.com";
alt="Advertiser Number Three";
banner="http://www.yourdomain.com/images/banner3.gif";
width="468";
height="60";
}
document.write(<center>);
document.write(<a href=\" + url + \" target=\"_blank\">);
document.write(<img src=\" + banner + \" width=)
document.write(width + height= + height + );
document.write(alt=\" + alt + \" border=0><br>);
document.write(</center>);
--></SCRIPT>
提交后看location
<form action=http://www.ychon.org/ method=get>
<input name=test value="中文 !#$%&()*+,/:;<=>?@[\]^`{|}~%Abc">