使用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
});