判断文本框的取值

 1 <!DOCTYPE html>
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title></title>
 6     <script src="jq/jquery-3.0.0.min.js"></script>
 7 </head>
 8 <body>
 9     <input type="text" value="" id="a1" />
10     <input type="text" value="" id="a2" />
11     <input type="text" value="" id="a3" />
12     <input type="text" value="" id="a4" />
13     <input type="button" value="确定" id="a5" />
14     <script>
15         $(document).ready(function () {
16             $("input[type='button']").click(function () {
17                 //alert("为空")
18                 //数组
19                 var num = $("input[type='text']");
20                 var aaa = "";
21                 for (var i = 0; i < num.length; i++) {
22                     if (num.eq(i).val() == "") {
23                         aaa += "第" + i + "个文本框为空";
24                         //a+=b   相当于   a = a+b
25                     }
26                 }
27                 alert(aaa);
28             });
29         });
30     </script>
31 </body>
32 </html>
原文地址:https://www.cnblogs.com/1412660554a/p/5917742.html