Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

jquery - $("#form1").validate is not a function

<script type="text/javascript">
<!--
$(document).ready(function() { 
      $("#form1").validate({ 
        rules: { 
         budget: {
            required: true,
             minlength:3
        } ,
       duration: {
            required: true,
            digits:true
        }, 
         town: {
            required: true,
             minlength:2

        },

       content: {
            required: true,
            minlength:300 

        }
         }, 
        messages: { 


        } 
          }); 
        });
        -->
</script>

Two jquery files are included.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="../common/jquery.validate.js"></script>

are included. There is nothing wrong with the inclusion.

I got an error message

$("#form1").validate is not a function What's wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Put the jQuery script tag before the script tag for validation

I just encountered this extremely frustrating error and lost the better part of an hour to it, for lack of a workable answer online. I confirmed in Firebug that I was hitting the CDN for both jQuery and validation.

In the end, changing this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>

to this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>

was all I needed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...