我进行分页,我希望在表单编号的文本字段中插入一个页面,当用户按下输入时将发送表单或将光标移出文本字段。
<form method="GET" action="/site">
<input type="text" name="page" />
</form>
我该如何解决这个问题?
///////////////编辑
如果我想指定一个变量$max
并在输入的字段中超过这个数字之后怎么办,那么什么都不会发生,即它没有发送表格?
你可以用纯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>