js简单的验证非空

View Code
 1 /* js验证 */
 2         $(".myform1").submit(function(){
 3             var isSub = true;
 4             var isFocus = false;
 5             $("input[type='text']").each(function() {
 6                 if($(this).val()==""){
 7                     if(!isFocus)
 8                     {
 9                         $(this).focus();
10                         isFocus = true;
11                     }
12                     isSub=false;
13                 }
14             });
15             $("select").each(function() {
16                 if($(this).val()==""){
17                     if(!isFocus)
18                     {
19                         $(this).focus();
20                         isFocus = true;
21                     }
22                     isSub=false;
23                 }
24             });
25             $("textarea").each(function() {
26                 if($(this).val()=="") {
27                     if(!isFocus)
28                     {
29                         $(this).focus();
30                         isFocus = true;
31                     }
32                     isSub=false;
33                 }
34             });
35             if(!isSub)
36             {
37                 alert("以上输入框均不能为空!");
38                 return false;
39             }else
40             {
41                 return true;
42             }
43         });

 

posted @ 2013-03-14 16:19  wsw0515  阅读(232)  评论(0编辑  收藏  举报