1.透明Flash代码
<param name="wmode" value="transparent">
2.加入收藏
<a href="JavaScript:window.external.addfavorite('http://www.yongfa365.com/blog','柳永法(yongfa365)\'Blog')" target="_top">加入收藏</a>
3.设为首页
<a href="#" target="_self" style="cursor:hand" onclick=this.style.behavior="url(#default#homepage)";this.sethomepage("http://www.yongfa365.com")>设为首页</a>
4.不同时间段显示不同问候语
<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>
5.改变IE地址栏的IE图标
我们要先做一个16*16的icon(图标文件),保存为index.ico。把这个图标文件上传到根目录下并在首页<head></head>之间加上如下代码:
<link REL = "Shortcut Icon" href="index.ico">
6.2秒后载入指定网页
<head>
<meta http-equiv="refresh" content="2;URL=http://www.yongfa365.com/blog">
</head>
7.显示当前日期,星期
<Script Language="JavaScript">
<!--
var today=new Date();
var strDate=(" "+today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日");
var n_day=today.getDay();switch(n_day)
{case 0:
{strDate=strDate+"(星期日)"}break;
case 1:
{strDate=strDate+"(星期一)"}break;
case 2:
{strDate=strDate+"(星期二)"}break;
case 3:
{strDate=strDate+"(星期三)"}break;
case 4:
{strDate=strDate+"(星期四)"}break;
case 5:
{strDate=strDate+"(星期五)"}break;
case 6:
{strDate=strDate+"(星期六)"}break;
case 7:
{strDate=strDate+"(星期日)"}break;
}
document.write(strDate);
// -->
</Script>
8.滚动代码
<marquee direction=up scrolldelay=200 scrollamount=1 width=206 height=207 onmouseover=this.stop() onmouseout=this.start()>大家好</marquee>
9.这个比较常用,一般用来处理长串连续英文撑破表格的问题
<td style="word-break:break-all">
10.图片渐渐显示出来
<SCRIPT language="JavaScript">
<!--
function makevisible(cur,which)
{
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=50
}
//-->
</SCRIPT>
<img src="yongfa.gif" style="filter:alpha(opacity=20)" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)">
11.删除文件
<%
set fso=server.CreateObject("scripting.filesystemobject")
filename1=server.MapPath("Pic")
if fso.fileexists(filename1) then
fso.deletefile filename1
end if
%>
12.mailto
<a href=mailto:[email protected];[email protected][email protected]&[email protected]&subject=您做的网页不错呀&body=再接再厉>E-mail</a>
13.内容显示or隐藏
<script language="JavaScript">
function show(i){
if (i.style.display == "none") {
i.style.display = "";
}else{
i.style.display = "none";
}
}
</script>
<div onClick="show(a1)" style="cursor:hand" >标题</div>
<DIV id=a1 style="DISPLAY: none">内容</DIV>
14.Window.open
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
15.两次确认是否删除(也不知这客户是怎么了)
<input type="button" name="Submit2" value="删除" onclick=" javasctipt:if (window.confirm('确定删除吗?')){if (window.confirm('确定删除吗?')){window.location.href='?action=del&id=<%=rs("id")%>'}}" >
16.按钮版确定删除吗?
<input type="button" name="Submit5" value="删除" onclick="if (confirm('您确定要删除嘛?')){window.location.href='?action=delok&id=<%=rs("id")%>';}" />
17.分类全选记录的函数
演示代码,只要checkbox的name一样就可以
调用时用checkall(this,'checkboxname')就可以
<script language=JavaScript>
function checkall(all,checkname)//用于判断全选记录的函数
{
var a = document.getElementsByName(checkname);
for (var i=0; i<a.length; i++) a[i].checked = all.checked;
}
</script>
<input type="checkbox" name="chkall" value="on" onClick="checkall(this,'question')">
18.打印本页
window.print()
19.引用upload.html<iframe>
<iframe src="upload.html" name="ad" width="280" height="22" scrolling="No"
frameborder="0" id="ad"></iframe>
20.引用eWebEditor
以下为编辑器的简单调用
添加:
<input type="hidden" name="content1" value="">
<iframe ID="eWebEditor1" src="../ewebeditor.asp?id=content1&style=standard" frameborder="0" scrolling="no" width="500" HEIGHT="350"></iframe>
修改:
<input type="hidden" name="content1" value="<%=Server.HTMLEncode(Rs("Content"))%>">
<iframe ID="eWebEditor1" src="../ewebeditor.asp?id=content1&style=standard" frameborder="0" scrolling="no" width="500" HEIGHT="350"></iframe>
21.插入Flash
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="684" height="316">
<param name="movie" value="images/111.swf">
<param name="wmode" value="transparent">
<param name="quality" value="high">
<embed src="images/111.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="684" height="316"></embed>
</object>
22.select改变时 跳转或执行操作
天气:<input name="weather" type="text" id="weather" size="5">
<select name="selectweather" onChange="weather.value=this.options[selectedIndex].value">
<option value="天气">天气</option>
<option value="睛">睛</option>
<option value="阴">阴</option>
<option value="小雨">小雨</option>
<option value="多云">多云</option>
<option value="阵雨">阵雨</option>
<option value="连阴">连阴</option>
<option value="小雪">小雪</option>
</select>
23.应付框架里登录的问题
'把下边这个放在登录页面head里
<script language="JavaScript">
if (self!=top){top.location='admin_login.asp';}
</script>
'或这样写
response.redirect " <script language='JavaScript'>top.location='login.asp'</script>"
24.Ctrl+Enter提交表单
<textarea name="co" cols="50" rows="10" onKeyDown="ctlSubmit(event);" style="width:97%;"></textarea>
<script>
function ctlSubmit(event) {
if (event.ctrlKey && event.keyCode == 13) { form1.submit() }
}
</script>
25.只能输入数字且数字要大于3
<script>
function min_in()
{
if (event.keyCode < 45 event.keyCode > 57){alert('同志只能输入数字,谢谢'); event.returnValue = false;}
}
function check_input(aaa)
{
if (aaa!=''&&aaa<3)
{
alert("哥哥,太少了");
return false;
}
}
</script>
<input type="text" name="money" value="" onKeypress="return min_in()" onblur="check_input(this.value)" >
26.全选与反选
function CheckOthers(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.checked==false)
{
e.checked = true;
}
else
{
e.checked = false;
}
}
}
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
e.checked = true;
}
}
30.改变obj的class属性值
<head>
<style>
.aa{color:red}
.bb{color:blue}
</style>
</head>
<body>
<form name=form1>
<input name=txt1 value="测试" class="aa">
<input type="button" onclick="form1.txt1.className='bb'" value="改变">
</form>
</dody>
31.如何在标题栏显示框架内页面的标题
top.document.title = document.title
32.脚本永不出错
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
</SCRIPT>
33.让输入框关闭自动完成(AutoComplete)功能
<form>
让输入框关闭自动完成(AutoComplete)功能<br />
测试方法:分别双击两个文本框看看有什么不一样<br />
默认:<input name="UserName" type="text" /><br />
关闭:<input name="UserName" type="text" autocomplete="off" /><br />
</form>
34. response.write 使用
response.write "<script LANGUAGE='javascript'>alert('成功~');location.herf='?page=1';</script>"
response.write "<script>window.location.href='zytm1.asp';</script>"
Response.Redirect("XXX.aspx");