2010-01-23 93 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