日期:2014-05-16  浏览次数:20375 次

请问多个Text非空校验怎么写校验函数?
我在提交按狃里是这么写的:return   IsNotNull4(txtInteger,txtFloat,txtPost,txtMail)

对应的函数是:
//某四个txt非空
function   IsNotNull4(txt1,txt2,txt3,txt4)          
{                  
                str=txt1.value;      
                if(str.length==0){        
                        alert( "对不起,该项不能为空! ");
                        txt1.focus();
                        return   false;
                }
                str=txt2.value;      
                if(str.length==0){        
                        alert( "对不起,该项不能为空! ");
                        txt2.focus();
                        return   false;
                }      
                str=txt3.value;      
                if(str.length==0){        
                        alert( "对不起,该项不能为空! ");
                        txt3.focus();
                        return   false;
                }        
                str=txt4.value;      
                if(str.length==0){        
                        alert( "对不起,该项不能为空! ");
                        txt4.focus();
                        return   false;
                }      
                return   true;
}

对应我还有IsNotNull1   -IsNotNull6   分别校验1个到6个txt非空
这方法太傻了吧

请问怎么写一个通用的呢?当然,不是所有text都要求非空的。。。
只是做为参数传入的text要求非空

------解决方案--------------------
L@_@K

<body>
<input type= "text " id= "txt01 " value= "1 " />
<input type= "text " id= "txt02 " value= "2 " />
<input type= "text " id= "txt03 " />
<input type= "text " id= "txt04 " value= "4 " />
<input type= "text " id= "txt05 " />
<input type= "text " id= "txt06 " valu