如何自动post提交?
How to automatic post submit?
我想在写入输入值时自动post。请问你能帮忙吗?表格如下:
<form method="post" action="searchresults.php">
<input type="text" name="searchresult">
<input type="submit">
</form>
这应该用 jQuery 来完成。
$('#toPost').keyup(function(){
$('#sub').click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="searchresults.php">
<input type="text" name="searchresult" id="toPost">
<input type="submit" id="sub">
</form>
我建议额外使用简单的超时。所以,当你写完后它会自动提交 - 使用上面的代码(来自 patwoj98)你可以只写 1 个字母直到提交。如果您想要输入超过 1 个字母,那么我会这样做:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var srt = null;
$("input[type=text]").on("keyup", function() {
srt != null && clearTimeout(srt);
srt = setTimeout(function(){
$("input[type=submit]").click();
}, 500);
});
});
</script>
<form method="post" action="searchresults.php">
<input type="text" name="searchresult">
<input type="submit">
</form>
这将是我实现这一点的方式。
我想在写入输入值时自动post。请问你能帮忙吗?表格如下:
<form method="post" action="searchresults.php">
<input type="text" name="searchresult">
<input type="submit">
</form>
这应该用 jQuery 来完成。
$('#toPost').keyup(function(){
$('#sub').click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="searchresults.php">
<input type="text" name="searchresult" id="toPost">
<input type="submit" id="sub">
</form>
我建议额外使用简单的超时。所以,当你写完后它会自动提交 - 使用上面的代码(来自 patwoj98)你可以只写 1 个字母直到提交。如果您想要输入超过 1 个字母,那么我会这样做:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var srt = null;
$("input[type=text]").on("keyup", function() {
srt != null && clearTimeout(srt);
srt = setTimeout(function(){
$("input[type=submit]").click();
}, 500);
});
});
</script>
<form method="post" action="searchresults.php">
<input type="text" name="searchresult">
<input type="submit">
</form>
这将是我实现这一点的方式。