常用Javascript精选(一)
作者:互联网
常用Javascript精选(一)
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>
标签:常用,return,Javascript,精选,form1,checkflag,var,false,true 来源: https://blog.51cto.com/lzhdim/2971501