开发者

Simplest form validation with the jQuery validation plugin wont work

I am trying to learn the jQuery validation plugin, so I created the simplest possible form, with the simplest possible validation code, but I still can't get it to开发者_运维知识库 work! When I click the submit button (leaving the field empty), I am sent to the default page as if the form had been submitted (the URL being "myurl.com/?name=") Below is the code, which I tried to do identical to that of a working tutorial.

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
    <script type='text/javascript' src='http://myurl.com/jquery.validate.js'></script>
    <script type='text/javascript' src='http://myurl.com/jquery.js'></script>

    <script type='text/javascript'>
    $(document).ready(function() {
        $("#test_form").validate();
    });
    </script>

    <script type='text/css'>
    label.error { color:Red; }
    </script>
</head>
<body>

<form id='test_form' action='' method='GET'>
    <p><label for='name'>Name</label><br />
    <input type='text' id='name' name='name' minlength='4' class='required' /></p>
    <p><input type='submit' value='Submit' /></p>
</form>

</body>
</html>


You have to load the main jquery.js before the plugin jquery.validate.js. Scripts are loaded in the order they're parsed.

The above results in a script error when trying to load the validate plugin, as jQuery is not loaded yet, the jQuery object to extend doesn't exist at the time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜