发送没有提交按钮的表单

Sending the form without the submit button

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

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

如何解决这个问题?

您可以使用纯 Javascript 执行此操作。这是一个粗略的伪代码,可以让你在 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>