1.自動選定文字框中的文本
<input type="text" name="mtext" size="100" width=20 value="待選中的文本,把滑鼠移上去看看:)" onmouseover="focus();select();">
2.輸入框限制
<input type="text" name="txtMonth" value=""
onBlur="if(this.value<1||this.value>12)
{alert('月份輸入有誤!');
this.focus();}>
3.限制輸入框只能輸入數字金額
<input type=text name=txtPostalCode onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnvalue = false;">
4.斷行符號轉下一行
<input onkeydown="if(event.keyCode==13)event.keyCode=9" name="text1">
5.彈出普通視窗及全屏展開
<script language="javascript" type="text/javascript">
var winH=window.screen.height -58;
var winW=window.screen.width -10;
</script>
<A href='javascript:;' onclick="window.open('search_grmx.asp?sid=<%=rs("sid")%>&rq_year=<%=year(rs("rq"))%>&rq_month=<%=month(rs("rq"))%>','newwindow','scrollbars=yes,top=1,left=1,width='+winW+',height='+winH+'')">連結文字
</a>
6.JS驗證
<SCRIPT language=javascript>
<!--
function checkform()
{
if (document.form1.skr.value=="") {
alert("必須輸入");
form1.skr.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
<form name="form1" method="post" action="enter.asp" onsubmit="return checkform();">
7.全選刪除
<script language="javascript">
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++){
if (field[i].disabled == false){
field[i].checked = true;
}
}
checkflag = "true";
return "取消全選";
}
else {
for (i = 0; i < field.length; i++){
field[i].checked = false;
}
checkflag = "false";
return "全 選";
}
}
// End -->
</script>
<input type="checkbox" name="list" value="<%=PIC_ID%>">
<input name="button" type=button onClick="this.value=check(this.form.list)" class="bottom" value="全 選">
<input name="Submit" type=submit class="bottom" value="刪 除">
8. text聚焦
<body text="#000000" bgcolor="#EFF1FD" onload="document.form1.txm.focus();" scroll="no">
9.限制只能輸入(0~9,a~z)﹕
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<SCRIPT language=javascript>
<!--
function ischinese(){
var reg=/[^a-z0-9_]/g
if (reg.test(document.form1.text3.value)){
alert("請輸入0-9和小寫a-z﹗");
form1.text3.focus();
return false;
}else{
return true;}
}
//-->
</SCRIPT>
</head>
<body>
<FORM name="form1" method="post" action="abc.asp" onsubmit="return ischinese();">
<input name="text3" type="text" size="15" value="">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>