2013-05-07 98 views
0

我使用文本框的jQuery插件..我在其他文本框插件工作正常......但是當我是個我的一些文本框提供細節的jquery不工作..的jQuery:密碼和確認密碼

這裏是我的代碼:

jQuery("#Merchant_Registration").validate({ 
       rules: { 
        UserN: "required", 
        pass: { 
         required: true, 
         minlength: 5 
        }, 
        confirm: { 
         minlength: 5, 
         equalTo: "#Password", 
        }, 
        question: "required", 
        answer: "required" 
       }, 
       success: function() { 
        xval = true; 
       }, 
       messages: { 
        UserN: "Please enter your last name", 
        pass: { 
         required: "Provide a password", 
         minlength: "Password length at least 5 characters!" 
        }, 
        confirm: { 
         minlength: "Password length at least 5 characters!", 
         equalTo: "Enter the same password as above" 
        }, 
        question: "Please enter a security question", 
        answer: "Please enter answer to security question" 
       } 
      }); 

      if (jQuery("#Merchant_Registration").valid()) { 
       return true; 
      } 

這裏是我的標記代碼:

<p> 
       <label>Username:</label> 
       <span class="field"> 
       <asp:TextBox ID="UserName" class="required" runat="server" name="UserN"></asp:TextBox> 
       </span> 
       </p> 

       <p> 
       <label>Password:</label> 
       <span class="field"> 
       <asp:TextBox ID="Password" class="required" runat="server" name="pass"></asp:TextBox> 
       </span> 
       </p> 

       <p> 
       <label>Re-type Password:</label> 
       <span class="field"> 
       <asp:TextBox ID="Password2" class="required" runat="server" name="confirm"></asp:TextBox> 
       </span> 
       </p> 

       <p> 
       <label>Security Question:</label> 
       <span class="field"> 
       <asp:TextBox ID="SecurityQ" class="required" runat="server" name="question"></asp:TextBox> 
       </span> 
       </p> 

       <p> 
       <label>Security Answer:</label> 
       <span class="field"> 
       <asp:TextBox ID="SecurityA" class="required" runat="server" name="answer"></asp:TextBox> 
       </span> 
       </p> 
在我的密碼字段

,它並沒有檢查用戶輸入是否是一樣的... ...和沒有按」 t顯示消息。

,而其他的文本框,當clickthe下一鍵時顯示的錯誤是「這個字段是必須的」,而不是預先設定的消息...

一些可以幫助一個你me..thank ..

回答

0

您需要使用name屬性爲驗證

例:

<form id="Merchant_Registration"> 
    <p> 
     <label>Username:</label> 
     <span class="field"> 
      <input ID="UserName" name="UserN"/> 
     </span> 
    </p> 

    <p> 
     <label>Password:</label> 
     <span class="field"> 
      <input ID="Password" name="Password"/> 
     </span> 
    </p> 

    <p> 
     <label>Re-type Password:</label> 
     <span class="field"> 
      <input ID="Password2" name="Password2"/> 
     </span> 
    </p> 

    <p> 
     <label>Security Question:</label> 
     <span class="field"> 
      <input ID="SecurityQ" name="SecurityQ"/> 
     </span> 
    </p> 

    <p> 
     <label>Security Answer:</label> 
     <span class="field"> 
      <input ID="SecurityA" name="SecurityA"/> 
     </span> 
    </p> 
</form> 

演示:Fiddle

+0

仍然相同..顯示的錯誤是「這是一個必填字段」... – aianLee 2013-05-07 04:30:29

+0

@aianLee這是因爲我用'UserName'和'UserN',檢查更新後的樣本 – 2013-05-07 04:41:18

+0

仍然是一樣的......我將文本框的名稱改爲userN,然後在jquery中調用它...但仍然是相同的...並且密碼和確認密碼不驗證。 – aianLee 2013-05-07 05:27:53