如果在Javascript中为空或空,我如何检查多个文本框?

时间:2016-03-05 08:12:54

标签: javascript php null textbox

如果在Javascript中为空或空,我如何检查多个文本框?我应该知道哪个文本框已填满

1 个答案:

答案 0 :(得分:0)

你可以使用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.

我希望这会有所帮助: - )