在输入字段中输入一定长度的文本后如何自动提交表格 [英] How to auto-submit form after entering text of certain length into input field

查看:64
本文介绍了在输入字段中输入一定长度的文本后如何自动提交表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找表单的自动提交功能,一旦用户在输入字段中输入了一定长度的文本(例如15个字符),就应该提交该表单.

I am looking for an auto-submit function for my form which should submit it once user enters text of certain length (lets say 15 chars) into an input field.

jQuery中是否有任何函数可以(非常短的间隔)不断(在很短的间隔内)检查输入字段中的文本长度,并在满足所需字符数时运行一个函数?有任何想法吗?

Is there any function in jQuery that would constantly (in very short intervals) check the length of the text in the input field and run a function once the required number of chars is met? Any ideas?

我正在寻找此功能: 用户使用表单输入页面-在输入字段上自动聚焦-用户使用扫描仪读取条形码-然后将条形码编号粘贴到输入字段中(不是键入,键入事件),然后自动提交表单.

I am looking for this functionality: User enters the page with the form - autofocuses on the input field - user reads a barcode with a scanner - then the barcode number is pasted in the input field (not keyup, keydown event) and the form is autosubmitted.

已解决: 使用此功能来捕获输入字段中的更改:

SOLVED: Used this function to catch changes in input field:

$(#inputField).bind('input propertychange', function(){
  dostuff();  
});

推荐答案

让我们将keyup事件处理程序附加到文本字段,而不是检查特定interval处输入字段中文本的长度.每次触发keyup事件时,我们都会检查长度是否超过15.如果超过,则我们将使用.submit() API提交表单.

Instead of checking for length of text in input field at particular interval, lets attach keyup event handler to the text field. Every time the keyup event is fired, we'll check if the length exceeds 15. If it does then we'll submit the form with .submit() API.

$('yourTextBoxSelector').on("change paste keyup", function(){
    if($(this).val().length >15){
        $('yourFormSelector').submit()
    }
});

更新:jQuery有一个事件paste.您可以使用它...

UPDATE : jQuery has an event paste. You can use it...

这篇关于在输入字段中输入一定长度的文本后如何自动提交表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆