使用jQuery循环遍历表单中的所有文本框 [英] Loop through all text boxes in a form using jQuery

查看:130
本文介绍了使用jQuery循环遍历表单中的所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像电子表格一样的表格。

I have a form which is laid out like a spreadsheet.

我想验证每个文本框中的文本,如果它不是数字,请更改背景文本框并显示一条消息。

I want to validate the text in each textbox and if it's not numeric, change the background of the textbox and display a message.

除了循环部分,我可以做任何事情。

I can do everything except for the looping part.

我猜这是...每个声明?

I'm guessing it's a for...each statement?

推荐答案

$('form input[type="text"]').each(function(){
        // Do your magic here
        if (this.value.match(/\D/)) // regular expression for numbers only.
            Error();
});

如果你有表格ID:

$('#formId input[type="text"]').each(function(){
        // Do your magic here
});

这篇关于使用jQuery循环遍历表单中的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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