回 帖 发 新 帖 刷新版面

主题:ctrl+enter的提交问题

<script language="javascript">
function checkform()
{ if(window.event.keyCode==13&&window.event.ctrlKey){
   if(checkadd()){
   document.form1.submit();
                                                     }
            }
  }
function checkadd()
  { if(document.form1.username.value.length==0)
  { alert("阁下不会没有名字吧!");
  window.form1.username.focus();
   return false;
   } else
   { return true;}
    if(document.form1.userword.value.length==0)
     { alert("阁下难道没话想说?");
  document.form1.userword.focus();
  return false;
  }else{
return true;
  }}
    </script>
<form name="form1" method="post" action="index.asp?action=add"onKeyDown="checkform();" onSubmit="return checkadd();">
现在的问题是不能对userword进行判断,还有会出现弹出两个“阁下不会没有名字吧”的对话框,我怎么改,请高手们请教~

回复列表 (共9个回复)

沙发

我建议用一个按钮的onclick来完成校验和提交,不要直接在form里面写

板凳

将onKeyDown="checkform();" onSubmit="return checkadd()
改一下:onKeyDown="checkform(this);" onSubmit="return checkadd(this)
试试吧!

会出现弹出两个“阁下不会没有名字吧”的对话框,可能是你返回了2个true

3 楼

To xiaoxia2004
加了还是没什么效果,还是不会对userword进行判断~~
你说我可能返回两个true那要怎么改~~
各位热心的兄弟们,来帮我看看这代码吧~~
谢了~~
还有methuselah兄
你说加个click要怎么个加法

4 楼

function checkadd()
  { if(document.form1.username.value.length==0)
  { alert("阁下不会没有名字吧!");
  window.form1.username.focus();
   return false;
   } else
       if(document.form1.userword.value.length==0)
     { alert("阁下难道没话想说?");
  document.form1.userword.focus();
  return false;
  }else{
return true;
  }
好了,现在的问题只剩下为什么会弹出两次“阁下不会没有名字吧”的对话框,请大家帮帮忙,谢了各位

5 楼

因为调了两次啊

6 楼

楼上的没说清:
            因为你的function checkadd() 调用了2次;
            不能对userword进行判断,是没遵循函数的应先定义后使用;(楼主已经明白了)

7 楼

最近开始上班,所以很少来。

8 楼

<script language="javascript">
function checkform()
{ if(window.event.keyCode==13&&window.event.ctrlKey){
  1 if(checkadd())
   2onKeyDown="checkform();"
调用了两次是说这两处调用的吗?那大家有什么好的修改办法~~
有加分的~~
希望大家帮我改改~~谢了~

9 楼

function checkadd()
  { if(document.form1.username.value.length==0)
   {
      alert("阁下不会没有名字吧!");
       window.form1.username.focus();
       return false;
   }
    if(document.form1.userword.value.length==0)
   {
     alert("阁下难道没话想说?");
     document.form1.userword.focus();
    return false;
   }
   return true;
  }

我来回复

您尚未登录,请登录后再回复。点此登录或注册