一些常用的辅助代码
点击返回上页代码:
<form>
<p><input type="button" value="返回上一步" onclick="history.back(-1)"></p>
</form>
弹出警告框代码:
<form>
<p><input type="button" value="弹出警告框" onclick="alertbutton()"></p>
</form>
<script language="javascript"><!--
function alertbutton(){window.alert("要多多光临呀!");}
// --></script>
点击打开新窗口
<form>
<p><input type="button" value="打开新窗口" onclick="newwindow()"></p>
</form>
<script language="javascript"><!--
function newwindow(){window.open("http://www.mcmx.com","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></script></body>
删除记录时弹出确认框:
<script language="vbscript">
a=msgbox("真的要删除该记录吗?",1,"注意")
if a=1 then
location="dodelete.asp?id=<%=id%>" //指向执行删除的页面dodelete.asp
else
history.go(-1)
end if
</script>
关闭打开的窗口
< a href="/" onclick="javascript:window.close(); return false;">关闭窗口</a>
清空input且选定
onclick="javascript:this.value=''" onfocus="this.select()" onmouseover="this.focus()"
右键屏蔽
<body oncontextmenu=self.event.returnvalue=false>
连串英文自动换行的解决方法 ie5.5
style="left: 0px; width: 100%; word-wrap: break-word" 你可修改为指定的大小如 200px
图片“重置”按钮
<script language="jscript">
function myreset()
{ document.login.reset();
document.login.focus();}
</script>
<img src="image/reclear.gif" width="69" height="20" style="cursor:hand" onfocus="this.blur()" onclick="myreset()"
画细线表格
<table style="border-collapse: collapse">
状态栏信息
<form>
<p><input type="button" value="状态栏信息" onclick="statusbutton()"></p>
</form>
<script language="javascript"><!--
function statusbutton(){window.status="要多多光临呀!";}
// --></script>
最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="command" value="minimize"></object>
<object id=hh2 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="command" value="maximize"></object>
<object id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="command" value="close"></object>
<input type=button value=最小化 onclick=hh1.click()>
<input type=button value=最大化 onclick=hh2.click()>
<input type=button value=关闭 onclick=hh3.click()>
本例适用于ie
隐藏状态栏里出现的link信息
<a href="http://"; onmouseover="window.status='none';return true">梦想天空</a>
文本框自动滚动条
<textarea name=words rows=18 cols=26 style="border:1 solid #000000;background-color:white; font-size:9pt; width:188; overflow:auto" wrap=hard></textarea>
全选并复制
<form name=test><input onclick="javascript:highlightall('test.select1')" type=button value=全选并复制><br><textarea name=select1 rows=3 cols=46>你好,欢迎您的光临!</textarea>
</form>
<script language=javascript>
<!--
var copytoclip=1
function highlightall(thefield) {
var tempval=eval("document."+thefield)
tempval.focus()
tempval.select()
if (document.all&©toclip==1){
therange=tempval.createtextrange()
therange.execcommand("copy")
window.status="contents highlighted and copied to clipboard!"
settimeout("window.status=''",1800)
}
}
//-->
</script>
屏蔽javascript错误
<script language="javascript">
<!--
function killerrors(){
return true;
}
window.onerror = killerrors;
-->
</script>
关闭子窗口时刷新父窗口
<script language="javascript">
<!--
self.opener.location.reload();
window.close()
-->
</script>
背景色变换
<form>
<p><input type="button" value="背景色变换" onclick="bgbutton()"></p>
</form>
<script>function bgbutton(){
if (document.bgcolor=='#00ffff')
{document.bgcolor='#ffffff';}
else{document.bgcolor='#00ffff';}
}
</script>
检查一段字符串是否全由数字组成
<script language="javascript"><!--
function checknum(str){return str.match(//d/)==null}
alert(checknum("1232142141"))
alert(checknum("123214214a1"))
// --></script>
1