drkbpwk609294 2017-01-02 11:26
浏览 10

当用户按下“插入”键时,如何提交表单?

How can I prompt for confirmation before submitting a form after they press the Insert key, and submit the form without confirmation when the user pushes the Enter/Return key ?

Summary of actions intended

  • INSERT : Prompt for confirmation. Submit form if confirmed.
  • ENTER : Submit form.

I have the following html form :

<form action="hhhhhhh.php" method="post" >
   <input type="text" name="DatInvNew"/>
   <input type="text" name="SumInvNew"/>
   <input type="text" name="KolInvNew"/>
   <input type="submit" value="next"/>
</form>
  • 写回答

2条回答 默认 最新

  • douxian4376 2017-01-02 11:37
    关注

    The following example does these things (as per the original question) :

    • INSERT : Prompt for confirmation. Submit form if confirmed.
    • ENTER : Submit form.

    document.onkeypress = function (e) {
        e = e || window.event;
        if(e.keyCode == 45) {
            if(confirm("Would you like to submit this form?")) {
                document.getElementById("myForm").submit();
            }
        } else if (e.keyCode == 13) {
            document.getElementById("myForm").submit();
        }
    };
    

    And change your html slightly :

    <form action="hhhhhhh.php" method="post" id="myForm">
        <input type="text" name="DatInvNew"/>
        <input type="text" name="SumInvNew"/>
        <input type="text" name="KolInvNew"/>
        <input type="submit" value="next"/>
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等