2012-01-20 187 views
1

我已經得到了他用來編輯用戶詳細信息的html表單。下面是它的工作原理 - 當點擊表格上的名稱時,我使用這種形式從數據庫加載數據,如?id=<theID>忽略jquery驗證

問題是,因爲這些字段對它們進行了驗證,所以它使我無法刪除該用戶,除非我已輸入所有數據。我的問題是:有沒有辦法讓'刪除'行動忽略驗證,只是繼續刪除?

這裏是整個代碼:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>example</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5"> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript" src="/js/jquery.js"></script> 
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script> 

    <style> 

* { 
    border: medium none; 
    /*font-family: "Arial",Helvetica,sans-serif; 
    font-size: small;*/ 
    margin: 0; 
    padding: 0; 
} 
</style> 

<style type="text/css"> 
     pre{background-color: #F5F2EE;} 

     label.error { 
     color: red; 
     padding-left: 3px; 
     font-weight: bold; 
} 
     </style> 

    <script type="text/javascript"> 

     $(document).ready(function() { 
      $("#myform").validate({ 
       rules: { 
        firstname: "required", 
        surname: "required", 
        address1: "required",      
        address4: "required",// simple rule, converted to {required:true} 
        address5: "required",      
        phone1: "required", 
        email: "required", 
        postcode1: "required", 
        postcode2: "required", 
        email: {    // compound rule 
         required: true, 
         email: true 
        }, 

       }, 
       messages: { 
        firstname: " *Required", 
        surname: " *Required", 
        address1: " *Required",      
        address4: " *Required",// simple rule, converted to {required:true} 
        address5: " *Required", 
        phone1: " *Required", 
        email: " *Required", 
        postcode1: " *Required", 
        postcode2: " *Required",              
       } 
      }); 
     }); 

    </script> 
</head> 



<body> 

    <div id="content"> 
     <div class="about"> 

      <h2>Check</h2> 

<form id="myform" action="" method="POST"> 
<table style="font-weight:bold; margin-top:5px; border: 1px solid #C6CFE1; padding-left:5px;background-color: #F5F2EE;">  
    <tr> 
    <td> 

     Name * 
    </td> 
    <td> 
     <input type="text" name="firstname" id="firstname" > 
    </td> 
    <td> 
     Home Phone * 
    </td> 
    <td> 
     <input type="text" name="phone1" id="phone1"> 

    </td> 

    </tr> 

    <tr> 
    <td> 
     Surname * 
    </td> 
    <td> 
     <input type="text" name="surname" id="surname" > 
    </td> 

    <td> 
     Mobile 
    </td> 
    <td> 
     <input type="text" name="phone2" id="phone2" value=""> 
    </td> 

    </tr> 

    <tr> 
    <td> 

     Address 1 * 
    </td> 
    <td> 
     <input type="text" name="address1" id="address1" > 
    </td> 
    <td> 
     Email * 
    </td> 
    <td> 
     <input type="text" name="email" id="email" value=""> 

    </td> 

    </tr> 

    <tr> 
    <td> 
     Address 2 
    </td> 
    <td> 
     <input type="text" name="address2" id="address2" value=""> 
    </td> 

    <td> 

    </td> 
    <td> 

    </td> 

    </tr> 


<tr> 
    <td> 
     Address 3 
    </td> 

    <td> 
     <input type="text" name="address3" id="address3" value=""> 
    </td> 
    <td> 
     Town * 
    </td> 
    <td> 
     <input type="text" name="address4" id="address4" value=""> 
    </td> 

    </tr> 




       <tr> 
        <td> 
         County * 
        </td> 
        <td> 
         <input type="text" name="address5" id="address5" value=""> 
        </td> 
        <td> 

         Postcode * 
        </td> 
        <td> 
         <input type="text" name="postcode1" id="postcode1" size="5"> 
         <input type="text" name="postcode2" id="postcode2" size="5"> 
        </td> 

       </tr> 




    <tr> 
    <td> 
    <input type="hidden" name="ID" value="3257" /> 
     &nbsp; 
    </td> 
    <td colspan="4"> 
     <input type="hidden" name="id" id="id" value="3257"> 
     <input type="submit" name="submit" id="submit" value="Submit update"> <input type="submit" name="delete" id="delete" value="Delete Record"> 


    </td> 
    <td>  
    </td> 
    <td> 
     &nbsp; 
    </td> 
    </tr> 

</table> 
</form> 
</body> 
</html> 

感謝您的幫助

回答

1

簡單,添加class="cancel"的刪除按鈕。這會導致它忽略驗證。

更多信息可以在這裏找到:Ignoring Jquery Validation

+0

哇,它的工作就像魅力 - 你是一個天才。我很感激 :) –