function checkInput()
{
  if(document.loginfrm.username.value=="")
  {
     alert("请输入用户名!");
     document.loginfrm.username.focus();
     return false;
  }
  if(document.loginfrm.pass.value=="")
  {
     alert("请输入密码!");
     document.loginfrm.pass.focus();
     return false;
  }
  return true ;
}<form method="post" action="../userlogin/UserLog.asp" name="loginfrm" onsubmit="return checkInput()">

解决方案 »

  1.   

    自动提交是因为你有input type=image,它的功能与input type=submit相似,当在form内其它text-input里按回车时,会自动执行onclick。(默认的onclick是执行form的onsubmit后再执行submit)
      

  2.   

    回JK_10000(JK1):
      你的意思我理解了,可是我在text中输入了参数,按回车后按道理应该是执行脚本函数,返回true的话就会执行submit,可是在我这里,脚本执行以后文本框的值就没有了,好像又提交到了本页,什么原因呢?
      

  3.   

    <input type=image style="cursor:hand" border="0" name="imageField" src="../images/but_login.gif" width="44" height="21" ">
    请注意,这一行里多了一个双引号,看一看是不是它造成了混淆。
    如果去掉这个多作的双引号,就是有三个image-button,其中的第一个没有onclick事件,所以会直接提交form。
      

  4.   

    <input type=image style="cursor:hand" border="0" name="imageField2" src="../images/but_reg.gif" width="44" height="21">
                        &nbsp;
                        <input type=image style="cursor:hand" border="0" name="imageField3" src="../images/but_refill.gif" width="44" height="21" onclick="javascript:login.reset()">不要用image控件,换成图片……
    你现在相当于有三个submit控件!
    <img style="cursor:hand" border="0" name="imageField2" src="../images/but_reg.gif" width="44" height="21">
                        &nbsp;
                        <img style="cursor:hand" border="0" name="imageField3" src="../images/but_refill.gif" width="44" height="21" onclick="javascript:login.reset()">
      

  5.   

    <input type=image style="cursor:hand" border="0" name="imageField" src="../images/but_login.gif" width="44" height="21" ">
    请注意,这一行里多了一个双引号,看一看是不是它造成了混淆。
    如果去掉这个多作的双引号,就是有三个image-button,其中的第一个没有onclick事件,所以会直接提交form。
    ----------------------------------
    如果你不去掉这个双引号,就没有问题了。----歪打正着不信你将你原贴拷贝后测试,是正常的!