1. 将彻底屏蔽鼠标右键:
oncontextmenu="window.event.returnValue=false"
将屏蔽<table>内容鼠标右键:
<table oncontextmenu=return(false)>XX</table>
2.取消选取(防止复制该内容):
<body onselectstart="return false">
<input type="text" name="name1" />
</body>
3.不准粘贴任何内容:
<body onpaste="return false">
<input type="text" name="name1" />
9.网页不会被缓存:
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者:<META HTTP-EQUIV="expires" CONTENT="0">
10.让弹出窗口总是在最上面:
<body onblur="this.focus();">
11.去掉滚动条:
让竖条没有: <body style="overflow:scroll;overflow-y:hidden">...</body>
让横条没有: <body style="overflow:scroll;overflow-x:hidden">...</body>
两个都去掉?更简单了<body scroll="no">...</body>
12.去掉点击图片链接产生的虚线:
<a href="#" onFocus="this.blur()">
<img src="/logo.jpg" border=0>
</a>
13.电子邮件处理提交表单:
<form name="form1" method="post" action=mailto:****@***.comenctype="text/plain">
<input type=submit />
</form>
14.在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()
15.设定打开页面的大小: <body onload="top.resizeTo(300,200);">
16.设定打开页面的位置<body onload="top.moveBy(300,200);">
17.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动:
<STYLE>
body{
background-image:url(/logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed
}
</STYLE>
18.检查一段字符串是否全由数字组成:
<script language="Javascript">
<!--
function checkNum(str)
{
return (str.match(//D/)==null);
}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// -->
</script>
19.获得一个窗口的大小:
document.body.clientWidth;
document.body.clientHeight;
20.怎么判断是否是字符?
if (/[^/x00-/xff]/g.test(s))
alert("含有汉字");
else
alert("全是字符");
21.TEXTAREA自适应文字行数的多少
<textarea name=s1 rows=1 cols=27 onpropertychange
="this.style.posHeight=this.scrollHeight">
</textarea>
22.日期减去天数等于第二个日期:
<script language=Javascript>
function cc(date,day)
{
//可以加上错误处理
var a = new Date(date);
a = a.valueOf();
a = a -day * 24 * 60 * 60 * 1000;
a = new Date(a);
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>
23.ENTER键可以让光标移到下一个输入框:
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
24.各种样式的光标
auto :标准光标
default :标准箭头
hand :手形光标
wait :等待光标
text :I形光标
vertical-text :水平I形光标
no-drop :不可拖动光标
not-allowed :无效光标
help :?帮助光标
all-scroll :三角方向标
move :移动标
crosshair :十字标
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize
25.在规定时间内跳转:
<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com">
</body>
4.防止复制:
oncopy="return false;" oncut="return false;"
5.IE地址栏前换成自己的图标:
<link rel="Shortcut Icon" href="favicon.ico">
6. 可以在收藏夹中显示出你的图标:
<link rel="Bookmark" href="favicon.ico">
7.关闭输入法:
<input style="ime-mode:disabled">
8.屏蔽功能键Shift,Alt,Ctrl
<script>
function look()
{
if(event.shiftKey)
alert("禁止按Shift键!"); //可以换成ALT CTRL
}
document.onkeydown=look;
</script>