$(document).ready(function () {
            $(".add").click(function () {
                $(":text").each(function () {
                    if (this.val == "") {
                        alert("请完整填写!");
                        return false;
                    }
                });
            });
        });
请教这段代码哪里出错了??

解决方案 »

  1.   

     $(document).ready(function () {
                $(".add").click(function () {
                    $(":text").each(function () {
                        if (this.value == "") {
                            alert("请完整填写!");
                            return false;
                        }
                    });
                });
            });
      

  2.   

    楼上正确
    if (this.value == "") 或者
    if ($(this).val() == "") 
      

  3.   

    楼上正确
    if (this.value == "") 或者
    if ($(this).val() == "")  
      

  4.   

    (this.val == "")应该是(this.val() == "")
      

  5.   


    $(document).ready(function () { 
        $(".add").click(function () { 
          $("#text").each(function () { 
            if (this.val() == "") { 
               alert("请完整填写!"); 
               return false; 
             } }); }); });
      

  6.   

    if(this.value=="")
    另外可以考虑用正则表达式