如何在Javascript中检查多个文本框是否为空或空?我应该知道填充了哪个文本框
您可以使用 jquery .each 函数,该函数带有指向所有类型为 "text" 的输入元素的选择器。像这样:
var nonNullInputs = new Array();
$(':text').each(function (index, value) {
if ($(this).val() != null) {
//get the id of the non null text input and push it for example in an array
//the index parameter returns the number of the input element by order in the form,
//the value parameter return the value
nonNullInputs.push($(this).attr('id'));
}
});
//now you have an array named nonNullInputs with all the inputs with type text which are not empty.
我希望这有帮助:-)