2010-01-23 98 views
1

MY .js文件:不工作jQuery验证形式

//rounded corners 
     $(document).ready(function() { 
      $("#topbar").corner("bl br 5px"); 
      $("#mainbar").corner("5px"); 
      $("#sidebar").corner("5px"); 
      $("#bottombar").corner("5px"); 
     }); 
    //form 
     $(document).ready(function(){ 
      $("#commentForm").validate({ 
       rules: { 
        FieldData0: { 
         required: true 
        }, 
        FieldData1: { 
         required: true, 
         email: true 
        }, 
        FieldData2: { 
         required: true 
        } 
       }, 
       messages: { 
        FieldData0: { 
         required: "* Required" 
        }, 
        FieldData1: { 
         required: "* Required", 
         minlength: "* 2 Characters Required." 
        } 
       } 
      }); 
     }) 

我的.html文件:

<div id="mainbar"> 
     <form id="commentForm" method="post" action="http://www.emailmeform.com/fid.php?formid=254816"> 
     <h2>Contact Form</h2> 
     <p> 
      <label for="name">Your Name</label> 
      <input type="text" id="name" name="FieldData0" /> 
     </p> 
     <p> 
      <label for="email">Your Email</label> 
      <input type="text" id="email" name="FieldData1" /> 
     </p> 
     <p> 
      <label for="message">Your Message</label> 
      <textarea type="text" id="message" name="FieldData2"></textarea> 
     </p> 
     <p> 
      <input id="button" type="submit" value="Submit"> 
     </p> 
     </form> 
    </div> 

活生生的例子:

http://weedcl.zxq.net/form.html

+0

你可以发布演示网址吗?为什么不把两个初始化放在同一个$(document).ready()块中? – 2010-01-23 15:09:09

+0

我是jquery noob。我知道如何做到这一点,而不会像我在自定义js中看到的那样破坏函数 – alexchenco 2010-01-23 15:21:16

+0

,我看到你有很多初始化,“$(document).ready(function(){”and“$(function(){ “是一样的...只是选择一个,把你所有的jQuery里面... – Reigel 2010-01-23 15:25:51

回答

2

看演示后,我注意到你的jquery pluings丢失了(至少在html中)。尝试添加:

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.js" /> 

之前包括custom.js在头文件中。表单验证通过插件提供,而不是由jQuery本身提供。

此外,我注意到角落插件也不存在 - download it并将其包含在头部。

您应该也可以这样做jQuery png fix

+0

谢谢,你的权利我错过了他们。 – alexchenco 2010-01-23 15:35:04