代码不完整啊!你可以这样  提交按钮 属性 改为button 不用submit  在js里根据条件 自己显示提交if (document.form1.username.value == "")
   {
       alert("用户名不能为空");
        //什么都不作
   }
else{
   document.form1.submit();//提交该表单
}

解决方案 »

  1.   

    第二个问题:
    <HTML>
    <HEAD>
    <script language="javascript">
    function check()  //检查输入的资料是否正确

    if (document.Form_Login.spp_Login.value =="") 

    alert("请填写用户!"); 
    document.Form_Login.spp_Login.focus(); 
    document.Form_Login.spp_Login.select()
    return false; 
    }
    if (document.Form_Login.spp_Password.value =="") 

    alert("请填写密码!"); 
    document.Form_Login.spp_Password.focus(); 
    document.Form_Login.spp_Password.select()
    return false; 
    }
    return true;
    }
    </script>
    </HEAD>
    <body>
    <FORM ACTION="logincheck.asp" METHOD=post NAME="Form_Login" onsubmit="return check()">
    <table cellspacing=2 cellpadding=2 width=279 border=0 align="center">
    <tr> 
    <td width=203> 
    <table height=75 cellspacing=0 cellpadding=0 border=0>
    <tr>
    <td align=right width=91 height=40>用 户:</td>
    <td width=117><input maxlength=10 size=15 name="spp_Login"></td>
    </tr>
    <tr>
    <td valign=top align=right height=35>密 码:</td>
    <td valign=top><input type=password maxlength=10 size=15 name="spp_Password"></td>
    </tr>
    </table>
    </td>
    <td width=76><input type="image" height=71 width=71 src="images/wblz_b_login001.gif" border=0 onclick="check()"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>第一个问题:<form name=a>
    <input type=text id=aaa value="2003/10/10">
    <input type=button value=click onclick=ch()>
    </form>
    <script language=javascript>
    function ch()
    {
     var b;
     b=sn_ChkDate1(document.a.aaa.value);
     if(b=='1')
      alert("成功");
     else
      alert("不成功");
    }
    //日期的检测     0:失败    1:成功 (YYYY/MM/DD)
    function sn_ChkDate1(vDate)
    {
    var IdateLen;
    var vTmpY="";
    var vTmpM="";
    var vTmpD="";
    var IStatus=0;
    if (vDate != "")
    IdateLen= vDate.length ;
    else
    {
    IdateLen=0;
    IStatus=0;
    }
    if ( IdateLen== 0)
    return 0;
    for (i=0;i<IdateLen;i++)
    { if (vDate.charAt(i)== '/')
    {
    IStatus++;
    }
    else if ((IStatus==0) && (vDate.charAt(i)!='/'))
    {
    vTmpY=vTmpY+vDate.charAt(i);
    }
    else if ((IStatus==1) && (vDate.charAt(i)!='/'))
    {
    vTmpM=vTmpM+vDate.charAt(i);
    }
    else if ((IStatus==2) && (vDate.charAt(i)!='/'))
    {
    vTmpD=vTmpD+vDate.charAt(i);
    }
    else if (IStatus>2)
    {
    return 0;
    }

    }
    year=new String (vTmpY);
    month=new String (vTmpM);
    day=new String (vTmpD);
    if (vTmpY.length!=4)
    {
    return 0;
    }
    if (vTmpM.length!=2)
    {
    return 0;
    }
    if (vTmpD.length!=2)
    {
    return 0;
    }
    if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
    {
    return 0;
    }
    if (!((year % 4)==0) && (month==2) && (day==29))
    {
    return 0;
    }
    if ((month<=7) && ((month % 2)==0) && (day>=31))
    {
    return 0;

    }
    if ((month>=8) && ((month % 2)==1) && (day>=31))
    {
    return 0;
    }
    if ((month==2) && (day>=30))
    {
    return 0;
    }

    return 1;
    }
    </script>
    只能输入数字也可以。
      

  2.   

    <input  name=pyear value="{year}" maxLength="4" 
    style="HEIGHT: 22px; WIDTH: 68px" onblur="if(this.value!=this.value.match(/\d{4}/))this.focus()">
            &nbsp;年 
            <input onblur="if(isNaN(this.value)||this.value<1||this.value>12)this.focus()" name=pmonth value="{month}" maxLength="2"   style="HEIGHT: 22px; WIDTH: 52px">
            &nbsp;月 
            <input name=pday value="{day}" maxLength="2"   
    style="HEIGHT: 22px; WIDTH: 58px" onblur="if(isNaN(this.value)||this.value<1||this.value>31)this.focus()" >
    第二个问题:
    在<form>中加上
    <form onsubmit="return checkFunctionName()">
      

  3.   

    只可输入数字。<input type=text value="这里" name=txt onkeypress="ch()">
    <script language=javascript>
    function ch()
    {
     if(event.keyCode>=48 &&event.keyCode<=57)
      return true;
     else
      event.keyCode=0;
    }
    </script>
      

  4.   

    //判断是否为合法的日期;不是返回true//要验证的form变量
    var validForm//判断是否为合法的日期;不是返回true
    function SelectIsNotDate(fieldYear, fieldMonth, fieldDay)
    {
      year = eval("validForm."+fieldYear+".value");
      month = eval("validForm."+fieldMonth+".value");
      day = eval("validForm."+fieldDay+".value");
      if (IsDateValide(year, month, day))
      { return false;}
      else
      { return true;}
    }// *************************************************
    // *                   私有函数                    *
    // *************************************************//是否为合法的日期;合法返回true
    function IsDateValide(year, month, day)
    {
      bi = (year%400==0 || (year%4==0 && year%100!=0));
      if ( ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) && day >= 1 && day <= 31)
        { correct = true;}
        else
        {
      if ( ( month == 4 || month == 6 || month == 9 || month == 11 ) && day >= 1 && day <= 30)
      { correct = true;}
      else
      {
    if (bi)
    { correct = ( day >= 1 && day <= 29 && month == 2);}
    else
    { correct = ( day >= 1 && day <= 28 && month == 2);}
      }
    }
      return correct;  
    }