无法在布尔值上创建guid属性

时间:2016-07-29 22:30:04

标签: javascript jquery forms validation guid

index = TextUtils.indexOf(text, needle); // for example $$username$$ above
text.replace(index, index + needle.length(), replacement);

这是我的客户端页面代码。当我试图在服务器(Apache tomcat)上部署它时,我收到以下错误

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<h1>USER REGISTRATION</h1>
<br>
<form class="for" name="ureg" method="post" action="">
<pre>
Name:              <input class="name" type="text" name="name"required><span id="errmsg5"></span><br><br>
User Name:         <input class="uname" type="text" name="un" required><span id="errmsg6"></span><br><br>
Password:          <input class="pass" type="password" name="pwd" name="pass" required><span id="errmsg7"></span><br><br>
Confirm Password:  <input class="cpass" type="password" name="cpass" required><span id="errmsg1"></span><br><br>
Email:             <input type="email" name="email" required><br><br>
Gender:            <input type="radio" name="gen" value="male" required>Male<input type="radio" name="gender" value="female">Female<br><br>
Country:           <select name="country" style="width: 175px;">
                    <option value="india">India</option>
                    <option value="pakistan">Pakistan</option>
                    <option value="sri lanka">Sri Lanka</option>
                    <option value="china">China</option>
                    <option value="china">Japan</option>
                    <option value="china">Bangladesh</option>
                    </select><br><br>
Mobile:            <input class="mob" type="number" name="mobile" required><span id="errmsg3"></span><br><br>
Age:               <input class="age" type="number" name="age" required><span id="errmsg2"></span><br><br>
D.O.B:             <input type="date" name="dob" required><br><br>
Address:           
<textarea rows="4" cols="50" name="addr" required></textarea><br><br>
Pincode:           <input class="pin" type="number" required><span id="errmsg4"></span><br><br>
<input id="submit" type="submit" value="SUBMIT">                <input id="reset" type="submit" value="RESET">
</pre>
</form>

<script type="text/javascript">
$(function () 
{   
        $(".pass").change(passcor());
        $(".cpass").change(passcor());
    function passcor() 
    {
        var password = $(".pass").val();
        var confirmPassword = $(".cpass").val();
        if (password != confirmPassword) 
        {
            alert("false");
            $("#errmsg1").text(" Password does not match");
            return false;
        }
        else
        {
            $("#errmsg1").text("");
            return true;
        }
    }
        $(".age").change(function ageval()
        {
            $("#errmsg2").text(" ");
            var n = $(".age").val();           
            if (n < 18) 
            {
                $("#errmsg2").text( " Age should be > 18");
                return false;
            }
            else
            {
                $("#errmsg2").text("");
                return true;
            }
        });
        $(".mob").change(function mobi() 
        {   
            $("#errmsg3").text( " ");
            var mobile = $(".mob").val();              
            if (mobile.length != 10) 
            {
                $("#errmsg3").text( " Not a valid number");
                return false;
            }
            else
            {
                $("#errmsg3").text("");
                return true;
            }

        });
        $(".pin").change(function pc() {
        $("#errmsg4").text( " ");
        var mobile = $(".pin").val();
        if (mobile.length != 6) 
        {
            $("#errmsg4").text( " Not a Valid Pincode");
            return false;
        }
        else
        {
            $("#errmsg4").text("");
            return true;
        }
    });
    $(".name").change(function namch() 
    {
        $("#errmsg5").text( " ");
        var name = $(".name").val();
        var pattern = new RegExp("^[A-z]+$");   
        if (!pattern.test(name)) 
        {
                $("#errmsg5").text( " Name should contain only letters");
                return false;
        }
        else
        {
            $("#errmsg5").text("");
            return true;
        }
    }); 
    $(".uname").change(function unch() 
    {       
        $("#errmsg6").text( " ");
        var uname = $(".uname").val();
        var pattern = new RegExp("^[A-z0-9]+$");        
        if (!pattern.test(uname)) 
        {
            $("#errmsg6").text( " User Name should contain only numbers and alphabets");
            return false;
        }
        else
        {
            $.post(
            {
                url:"UNcheck",
                data:
                {
                    name:"un",
                    value:uname
                },
                success :function(value)
                {
                    if(value=="true")
                    {
                        alert("found new");
                        $("#errmsg6").text("");
                        return true;
                    }
                    else
                    {
                        $("#errmsg6").text( " User Name already taken");
                        return false;
                    }
                }
            });
        }
    });
    $(".pass").change(function passval() 
    {
        $("#errmsg7").text(" ");
        var pass = $(".pass").val();
        if(pass.length>8)
        {
            var caps = /[A-Z]/.test(pass);
            var small = /[a-z]/.test(pass);
            var num= /[0-9]/.test(pass);
            var sp=/\W|_/.test(pass);
            if(caps&&small&&num&&sp)
            {
                $("#errmsg7").text("");
                return true;
            }
            else
            {
                $("#errmsg7").text("Password should be of minimum 8 characters and contain atleast 1 upper case, 1 lower case, 1 digit and 1 special characters");
                return false;
            }
        }
        else
        {
            $("#errmsg7").text("Password should be of minimum 8 characters and contain atleast 1 upper case, 1 lower case, 1 digit and 1 special characters");
            return false;
        }
    });
    $(".for").submit(function()
    {
        if(passval()&&unch()&&namch()&&pc()&&mobi()&&ageval()&&passcor())
        {
            var sendat=$(".form :input").serialiazeArray();
            alert(sendat);
            $.post(
            {
                url:"InputData",
                data:sendat
            });
        }
    }); 
});
</script>
</body>
</html>

jQuery.Deferred exception: Cannot create property 'guid' on boolean 'true' TypeError: Cannot create property 'guid' on boolean 'true' at Object.add (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:7797) at HTMLInputElement.<anonymous> (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:7602) at Function.each (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:2:2815) at r.each (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:2:1003) at wa (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:7578) at r.on (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:13467) at r.fn.(anonymous function) [as change] (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:4:6349) at HTMLDocument.<anonymous> (http://localhost:8080/FormValidation/index.html:38:14) at j (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:2:29568) at k (http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js:2:29882) undefined 是什么原因以及如何解决这个问题。我试着阅读它,但大部分都没有,我知道GUID是全局唯一标识符。但问题究竟是为什么造成的?

2 个答案:

答案 0 :(得分:1)

这一行:

$( “通”)发生变化(passcor());

passcor()返回true,然后传递给change()函数。 change()期待一个函数,而不是布尔值:https://api.jquery.com/change/

我的假设是你不想在传入之前调用该函数(删除()括号):

$( “通”)发生变化(passcor);

答案 1 :(得分:1)

这对我有用。而是在jquery中调用。我把html本身的passcor()称为

Password:          <input class="pass" type="password" name="pwd" name="pass" onChange=passcor() required><span id="errmsg7"></span><br><br>
Confirm Password:  <input class="cpass" type="password" name="cpass" onChange=passcor() required><span id="errmsg1"></span><br><br>