Javascript:输入不适用于提交密码

标签 javascript html passwords submit

我无法使以下代码正常工作:当我在文本框中按回车键时,该函数未被调用。我不明白为什么...

<form>
<p align="center">
<input type="password" class="password" name="text1" onkeypress="submitonenter(text1.value,"money","cash",event)" /><br>
<input type="button" value="Enter" style="width: 100px" name="Enter" onclick=javascript:validate(text1.value,"money","cash") />
</p>
</form>

<script type="text/javascript">
    function submitonenter(text1,text2,text3,evt) {
        evt = (evt) ? evt : ((window.event) ? window.event : "")
        if (evt) {
            // process event here
            if ( evt.keyCode==13 || evt.which==13 ) {

 if (text1==text2)
 load('money/welcome.html');
 else 
 {
  if (text1==text3)
  load('cash/welcome.html');
   else
   {
   load('failure.html');
   }
 }

            }
        }
    }
</script>

<script language = "javascript">
function validate(text1,text2,text3)
{
 if (text1==text2)
 load('money/welcome.html');
 else 
 {
  if (text1==text3)
  load('cash/welcome.html');
   else
   {
   load('failure.html');
   }
 }
}
function load(url)
{
 location.href=url;
}
</script>

最佳答案

我完全不确定您为什么需要 submitOnEnter 函数。

为什么不直接将输入 type='button' 更改为 type='submit' 并将 onclick 关键字更改为 提交?

编辑: 抱歉,当然 'onsubmit' 需要放在表单标签中,而不是输入中。 提供以下内容:

<form onsubmit=validate(text1.value,"money","cash") >
  <p align="center">
    <input type="password" class="password" name="text1" /><br>
    <input type="submit" value="Enter" style="width: 100px" name="Enter" />
  </p>
</form>

关于Javascript:输入不适用于提交密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3822614/

相关文章:

javascript - 在 SVG 路径上找到一个点

html - anchor 元素 <a> 的填充溢出

html - 试图在类别下的页面上显示标题

security - 修改SVN密码命令行

ios 密码字段 - 需要在设置包中进行设置

javascript - 取值,用输出更新字段

javascript - jquery 设置的复选框和数字字段出现一瞬间,然后突然消失

javascript - Knockout js 嵌套控制流绑定(bind)不起作用

html - CSS p {Indent} 留空

MySQL 5.6.26 (Windows 8.1 x64) : Trouble with setting a password for the root MySQL user