首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

请教多个Text非空校验如何写校验函数

2012-02-11 
请问多个Text非空校验怎么写校验函数?我在提交按狃里是这么写的:returnIsNotNull4(txtInteger,txtFloat,tx

请问多个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 " value= "6 " />
<script type= "text/javascript ">


<!--
function IsNotNull()
{
for (var i=0; i <arguments.length; i++)
{
if (arguments[i].value.length == 0)
{
alert( "对不起,该项不能为空! ");
arguments[i].focus();
return false;
}
}
return true;
}
IsNotNull(txt01, txt03, txt05);
//-->
</script>
</body>
[解决办法]
http://community.csdn.net/Expert/TopicView3.asp?id=5568847

热点排行