【问题标题】:Sending the form without the submit button发送没有提交按钮的表单
【发布时间】:2019-09-17 13:18:52
【问题描述】:

我进行分页,我想在表单编号的文本字段中插入页面和表单,当用户按下回车键或将光标移出文本字段时,表单将发送。

<form method="GET" action="/site">
<input type="text" name="page" />
</form>

我该如何解决这个问题?

【问题讨论】:

    标签: html forms send


    【解决方案1】:

    你可以用纯 Javascipt 做到这一点。下面是一个粗略的伪代码,让您在 IIFE 中开始:

    <form method="GET" action="/site">
        <input type="text" name="page" id="yourInput" />
    </form>
    
    <script>
    (function() {
        var el = document.getElementById('yourInput'); //Get your input by ID
        el.onblur = function() { // when focus lost...
            this.form.submit(); // submit the form
        }
    })();
    </script>
    

    【讨论】:

    • 我收到来自控制台的通知 - Uncaught TypeError: Cannot set property 'onblur' of null
    • @polyman 这意味着没有 ID 为 yourInput 的元素,或者任何你命名的元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    相关资源
    最近更新 更多