偶自己写的javascript脚本

原创 2006年05月18日 18:47:00
乱七八糟,我能看懂就行了!
<script language="javascript">
       function chkScore()
       {
              if (document.all.form1.<%=ThesisScore%>.value=="0")
              {
                     window.alert("请为学生选择成绩");
                     return false;
              }
              else
              {
                     return true;
              }
       }
</script>
 
 
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<SCRIPT Language="Javascript">      
       function f(){
              var p = document.all("aa").length;
              for(i=0;i<p;i++){
                     if (document.all("aa")[i].checked == true){
                     var q = i;
                     break;
                     }
              }
              var k = document.all("aa")[q].value;
              alert(k);
       }
</SCRIPT>
 
</head>
 
<body>
<form action="" name="form1">
<input type="radio" name="aa" value="00">
<input type="radio" name="aa" value="11">
<input type="radio" name="aa" value="22">
<input type="radio" name="aa" value="33">
<input type="button" onclick="f()" value="KK">
</form>
</body>
</html>
 
 
 
       function chkdate(datestr){
       //writed by zn 2006.04.30
              if (datestr==""){
                      alert("必须输入日期")
                      return false;
              }
              var lthdatestr
              lthdatestr= datestr.length ;
              var tmpy="";
              var tmpm="";
              var tmpd="";
              //var datestr;
              var status;
              status=0;
      
              for (i=0;i<lthdatestr;i++){
                      if (datestr.charAt(i)== '-'){
                                   status++;
                      }
                      if (status>2){
                                   alert("请用两个'-'作为分隔符!如2005-02-01");
                                   return false;
                      }
                      if ((status==0) && (datestr.charAt(i)!='-')){
                                   tmpy=tmpy+datestr.charAt(i)
                      }
                      if ((status==1) && (datestr.charAt(i)!='-')){
                                   tmpm=tmpm+datestr.charAt(i)
                      }
                      if ((status==2) && (datestr.charAt(i)!='-')){
                                   tmpd=tmpd+datestr.charAt(i)
                      }
              }
             
              year=new String (tmpy);
              month=new String (tmpm);
              day=new String (tmpd)
              //tempdate= new String (year+month+day);
              //alert(tempdate);
              if (isNaN(tmpy)==true || isNaN(tmpm)==true || isNaN(tmpd)==true){
                      alert("日期只能为数字!");
                      return false;
              }
              if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
              {
                      //alert("请用'-'作为分隔符!");
                      alert("错误的日期格式!");
                      return false;
                      }
              if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
              {
                      alert ("错误的月份或天数!");
                      return false;
                      }
              //if (!((year % 4)==0) && (month==2) && (day==29))           
              if (!((tmpy%4==0&&tmpy%100!=0)||(tmpy%400==0))&& (month==2) && (day==29)){
                      alert ("这一年不是闰年,只有28天!");
                      return false;
                      }
              if ((month<=7) && ((month % 2)==0) && (day>=31))
              {
                      alert ("这个月只有30天!");
                      return false;
                      }
              if ((month>=8) && ((month % 2)==1) && (day>=31))
              {
                      alert ("这个月只有30天!");
                      return false;
                      }
              if ((month==2) && (day==30))
              {
                      alert("2月永远没有这一天!");
                      return false;
              }     
              return true;
       }
 
 
 
 
 
<script language="javascript">
       function chkstr()
       {
       var obj = document.form1.sfz;
              if(obj.value=="")
              {
                     alert("不能为空!");
                     document.form1.focus();
                     return false;
              }
              else if (obj.value.length==15)
              {
                     if(isNaN(obj.value)==true)
                     {
                            alert("身份证号码只能为数字且为半角!");
                            document.form1.focus();
                            return false;
                     }                  
              }
              else if (obj.value.length==18)
              {
                     for(i=0;i<17;i++)
                     {
                            if(isNaN(obj.value.charAt(i))==true)
                            {
                                   alert("如果您是18位的身份证,前17位只能为数字且为半角!");
                                   document.form1.focus();
                                   return false;
                            }
                     }
                     if(isNaN(obj.value.charAt(17))==true)
                     {
                            if (obj.value.charAt(17)!="X")
                                   {
                                          alert("如果您是18位的身份证,第18位只能为数字或X且为半角!");
                                          document.form1.focus();
                                          return false;
                                   }
                     }
              }
              else
              {
                     alert("身份证位数不正确!应该为15或18位且为半角!");
                     document.form1.focus();
                     return false;
              }
 
       }
 
       function f()
       {
              if(document.form1.sfz.value.search(/^/d{15}(/d{2}[0-9Xx])?$/)==-1)
              {
                     alert('你输入的身份证号码不准确,请注意只能为半角!');
                     document.form1.focus();
                     return false;
              }
       }
 
</script>
 
 
 
<script language=javascript>
       function msgbox() 
       {
              var q = document.all("ftmoney").length;
              var Flg = false;
              for(i=0;i<q;i++)
              {
                     if(document.all("ftmoney")[i].value>15)
                     {
                            Flg=true;
                            break;
                     }
              }
              if(Flg==true)
              {
                     if (window.confirm('存在学生分摊的费用大于15元的情况,您确定要继续吗?'))
                     {
                            document.form1.submit();
                     }
                     else
                     {
                            return false;
                     }
              }
              else
              {
                     if (window.confirm('您确定要分摊费用吗?'))
                     {
                            document.form1.submit();
                     }
                     else
                     {
                            return false;
                     }
              }
       }
</script>
 
 
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<style type="text/css">
BODY
{
    "宋体";
    FONT-SIZE: 9pt;
    BACKGROUND-COLOR: #E3F1FF;
}
TD
{
    "宋体";
    FONT-SIZE: 9pt;
}
</style>
<script language="javascript">
       //通用表单验证函数
       //需要为表单每个要验证的添加两个属性,nType 由数字和字母n组成,先是数字,然后是字母n
       function chkform(form)
       {
              var n_i = form.length;
              for(i=0;i<n_i;i++)
              {
                     var strType = form(i).nType;
                     if (strType == undefined) strType = "";
                     if (strType.indexOf("n") != -1)
                     {
                            //检测是否为空
                            if (form(i).type == "checkbox")
                            {
                                   alert(form(i).name);
                                   var k = form(i).name;
                                   var q = form.all(k).length;
                                   var p = 1;
                                   for (j=0;j<q;j++)
                                   {
                                          alert(form(i));
                                          if (form(i)[j].checked == true)
                                          {
                                                 p = 2;
                                                 break;
                                          }
                                          else
                                          {
                                                 p = 3;
                                          }
                                   }
                                   if (p == 3)
                                   {
                                          alert('必须选择一项!');
                                          form(i).focus();
                                          return false;                               
                                   }
                            }
                            else
                            {
                                   if (form(i).value=='')
                                   {
                                          alert('该项不能为空!');
                                          form(i).focus();
                                          return false;
                                   }
                            }
                     }
                     strType = parseInt(strType);               
                     if (strType=='1')
                     {
                            //检测是否是半角数字
                            if (form(i).value.search(/^[0-9]+$/)==-1)
                            {
                                   alert('请输入数字,注意是半角!');
                                   form(i).focus();
                                   return false;
                            }                  
                     }
 
                     if (strType=='2')
                     {
                            //检测是否是全角数字
                            if (form(i).value.search(/^[0-9]+$/)==-1)
                            {
                                   alert('请输入数字,注意是全角!');
                                   form(i).focus();
                                   return false;
                            }                  
                     }
 
                     if (strType=='3')
                     {
                            //检测是否为半角字母
                            if (form(i).value.search(/^[a-zA-Z]+$/)==-1)
                            {
                                   alert('请输入字母,注意必须是半角!');
                                   form(i).focus();
                                   return false;
                            }                  
                     }
 
                     if (strType=='4')
                     {
                            //检测是否为半角字母及下划线
                            if (form(i).value.search(/^[a-zA-Z_]+$/)==-1)
                            {
                                   alert('请输入字母及下划线_,注意必须是半角!');
                                   form(i).focus();
                                   return false;
                            }                  
                     }
 
                     if (strType=='5')
                     {
                            //身份证验证
                            if (form(i).value.search(/^/d{15}(/d{2}[0-9Xx])?$/)==-1)
                            {
                                   alert('请输入正确的身份证号码,注意是半角!');
                                   form(i).focus();
                                   return false;
                            }
                     }
 
                     if (strType=='6')
                     {
                            //邮件验证
                            if (form(i).value.search(/^.+@/w+(./w+)+$/)==-1)
                            {
                                   alert('请输入正确的邮件,注意是半角!');
                                   form(i).focus();
                                   return false;
                            }
                     }
 
                     if (strType=='7')
                     {
                            //邮政编码验证
                            if (form(i).value.search(/^/d{6}$/)==-1)
                            {
                                   alert('请输入正确的邮政编码,注意是半角!');
                                   form(i).focus();
                                   return false;
                            }
                     }
 
                     if (strType=='8')
                     {
                            //单个电话号码验证
                            if (form(i).value.search(/^(00/d{1,3}-){0,1}0/d{3}-/d{7,8}$/)==-1)
                            {
                                   alert('请输入正确格式的电话号码,注意是半角!');
                                   form(i).focus();
                                   return false;
                            }
                     }
 
                     if (strType=='9')
                     {
                            //中文验证
                            if (form(i).value.search(/^[/u0391-/uFFE5]+$/)==-1)
                            {
                                   alert('请输入中文!');
                                   form(i).focus();
                                   return false;
                            }
                     }
 
                     if (strType=='10')
                     {
                            //用户名验证,字母数字及下划线
                            if (form(i).value.search(/^/w{3,20}$/)==-1)
                            {
                                   alert('请输入正确的用户名,只能是字母数字及下划线!');
                                   form(i).focus();
                                   return false;
                            }
                     }                  
              }
//     form.submit();
       }
 
</script>
</head>
<body>
<form name="form1" action="aa.html">
用户名:<input type="text" name="" nType="6">[数字字母下划线 3-20位]<br><br>
姓名:<input type="text" name="" nType="">[中文]<br><br>
性别:<input type="radio" name="" checked>男<input type="radio" name="" nType="">女<br><br>
年龄:<input type="text" name="" nType=""><br><br>
电子邮件:<input type="text" name="" nType=""><br><br>
身份证号码:<input type="text" name="" nType=""><br><br>
个人爱好:<textarea name="" rows="3" cols="10" nType=""></textarea><br><br>
收入:
              <input type="checkbox" id='d' name="dd">1000以下
              <input type="checkbox" id='d' name="dd">1000-1500
              <input type="checkbox" id='d' name="dd">1500-2500
              <input type="checkbox" id='d' name="dd" nType="n">2500以上<br><br>
 
<input type="button" value='确定' onclick="chkform(this.form)">
<input type="reset" value="重置">
</form>
</body>
</html>
 
<script language="javascript">
//     alert(form1.all("d").length)
</script>

相关文章推荐

使用chrome extend写一个操作京东网页的JavaScript脚本

一个最简单的chrome extend最要由两个文件构成,一个是配置文件mainfest.json,另一个是操作的JS文件,这个JS是在mainfest.js里面引入的。...

JavaScript学习笔记39-用JavaScript写Selenium脚本

前面38篇文章介绍了JavaScript的基础知识和简单应用练习。学了这个脚本语言的基础知识之后,我们的目的是什么?当然是应用。这篇,我们就来介绍如何写你的第一条JavaScript+Selenium...

#学习笔记#(5)表格奇偶行颜色样式JavaScript+CSS+HTML

表格奇偶行样式 .odd { background:#ffffee; } .even { background:#fff38f; } .first { background:red;...

[JavaScript] 11.JS 偶识【正则表达式】[2]

关于【正则表达式】的认识是基于JavaScript上的,在先前的J2SE博客整理阶段,并未直接列出,经过长时间的接触和使用,不断刷新对其认识程度,方才在此时总结归纳出,不断给予自己挑战是证明自己不断向...

JavaScript实战-DOM操作之奇偶变色表格

JavaScript实战-DOM操作之奇偶变色表格 全部代码如下: 效果如下:

JavaScript查找奇偶异常值

JavaScript查找奇数或偶数数组中的异常值。
  • esir82
  • esir82
  • 2016年08月20日 08:01
  • 330

JavaScript实战-DOM操作之奇偶变色表格2

JavaScript-奇偶变色表格+鼠标变色表格 需要给tbody中的每一个tr加事件。 全部代码如下: 效果如下:...

JavaScript脚本实现单条微博自动重复转发

本博客通过浏览器自带控制台执行简单的JS脚本实现微博转发。菜鸟水平,仅供参考,若有雷同,请一笑置过。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:偶自己写的javascript脚本
举报原因:
原因补充:

(最多只允许输入30个字)